0

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.

It show's like this:

If I click the Menu-button on the right in the Toolbar, the Android Soft Navigation is showing.

Like this:

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!

1 Answers1

0

You can't hide those buttons it's there because of security purposes for eg: Suppose suppose if you are in a FullScreen state & the user wants to exit the application like pressing Home button. He should able to do that easily & in no way your app should obstruct that.

You can't hide them completely but can draw behind them by altering System UI Visibility flags from

getWindow().decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
kaustubhpatange
  • 442
  • 5
  • 13
  • Are your sure? I have some Apps on my phone and they run in Fullscreen without Navigation-Bar. The Navigation Bar only show, if I touch or swipe down on the top of my screen. But not If I touch the Menu Bar. And the Buttons are invisible in my app, only if I click on the Menu toggle. – MarkZethQ Feb 22 '21 at 16:23