I'm new in Android Studio and I have a small problem.
I build a simple OSM Map View with Markers and it works great but now i want to add a Toolbar to the Content.
If I click the Menu-button on the right in the Toolbar, the Android Soft Navigation is showing.
I searched for some houres but nothing is fix the Problem. For example: Content going behind Navigation Bar Content goes behind soft navigation bar for api 21 and up
Map.kt
var toolbarIconsColor = Color.parseColor("#FFFFFF")
var overflowIcon = toolbar_home.getOverflowIcon();
toolbar_home.setOverflowIcon(
overflowIcon?.let {
getTintedDrawable(
toolbar_home.getContext(),
it,
toolbarIconsColor
)
}
)
toolbar_home.setTitle("MAP")
toolbar_home.setBackgroundColor(Color.parseColor("#2ebf91"))
toolbar_home.setTitleTextColor(Color.parseColor("#FFFFFF"))
toolbar_home.setNavigationOnClickListener {
// do something when click navigation
}
toolbar_home.inflateMenu(R.menu.menu_home)
toolbar_home.setOnMenuItemClickListener {
when (it.itemId) {
R.id.action_add -> {
// do something
true
}
else -> {
super.onOptionsItemSelected(it)
}
}
}
override fun onWindowFocusChanged(hasFocus: Boolean) {
super.onWindowFocusChanged(hasFocus)
if (hasFocus) {
// Standard Android full-screen functionality.
window
.decorView.systemUiVisibility = (View.SYSTEM_UI_FLAG_LAYOUT_STABLE
or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
or View.SYSTEM_UI_FLAG_FULLSCREEN
or View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
)
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
}
}
fun getTintedDrawable(
context: Context,
inputDrawable: Drawable,
@ColorInt color: Int
): Drawable {
val wrapDrawable = DrawableCompat.wrap(inputDrawable)
DrawableCompat.setTint(wrapDrawable, color)
DrawableCompat.setTintMode(wrapDrawable, PorterDuff.Mode.SRC_IN)
return wrapDrawable
}
activity_map.xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical">
<org.osmdroid.views.MapView
android:id="@+id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:focusable="true" />
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar_home"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
/>
</FrameLayout>
styles.xml (Make the Soft-Navigation transparent, but the buttons are always visible)
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="Theme.Transparent" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowNoTitle">true</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:textColorPrimary">#FFFFFF</item>
<item name="android:itemBackground">#2ebf91</item>
<item name="actionOverflowMenuStyle">@style/OverflowMenu</item>
<item name="android:statusBarColor">@android:color/transparent</item>
<item name="android:navigationBarColor">@android:color/transparent</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
</style>
<style name="OverflowMenu" parent="Widget.AppCompat.Toolbar">
<item name="overlapAnchor">false</item>
<item name="android:overlapAnchor">false</item>
</style>
I hope someone can help me :)
Thank you in advance for your response!