1

Layout used in the Activity (for GoogleMap)

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:tools="http://schemas.android.com/tools"
            android:id="@+id/cl_map"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

        <fragment
                android:id="@+id/fr_map"
                android:name="com.google.android.gms.maps.SupportMapFragment"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                tools:context=".ui.activity.MapActivity" />

    </androidx.coordinatorlayout.widget.CoordinatorLayout>

In the very same Activity, this was how a snack bar was created, when a marker was clicked.

override fun onMarkerClick(p0: Marker?): Boolean {
    Snackbar.make(findViewById(R.id.cl_map), "Hello World", Snackbar.LENGTH_INDEFINITE).show()
    // finding android.R.id.content does not work either
    // Snackbar.make(findViewById(android.R.id.content), "Hello World", Snackbar.LENGTH_INDEFINITE).show()
    return false
}

Here are the screenshots and a few symptoms:
for the initial click of a marker: enter image description here Please pay attention to the black slim line. That was the snack bar.

But if I clicked anywhere in the map body, instead of a marker, the snack bar became normal.

enter image description here

What's more, if I set the uiSettings.isMapToolbarEnabled false, the default toolbar was hidden, but the snack bar never showed up. I could not even saw the black slim line at all, no matter what click I have.

this.googleMap?.uiSettings?.isMapToolbarEnabled = false

One similar question here. The phone I took screenshots from was a Nexus 5. Native Android 6.0.1, the latest OS a Nexus 5 can support.

Leon
  • 811
  • 10
  • 21

1 Answers1

0

The root cause has pretty much been found. In a full screen mode, the snack bar is hidden by SystemUI. One can easily replicate this problem here.

In my case, here are the snippets that cause the problem

override fun onWindowFocusChanged(hasFocus: Boolean) {
    super.onWindowFocusChanged(hasFocus)
    if (hasFocus) hideSystemUI()
}

private fun hideSystemUI() {
    window.decorView.systemUiVisibility = (
            View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
                    // or View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                    // or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                    // or View.SYSTEM_UI_FLAG_FULLSCREEN
                    // to hide the nav bar and status bar
                    or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                    or View.SYSTEM_UI_FLAG_FULLSCREEN)
}

Mode SYSTEM_UI_FLAG_IMMERSIVE and SYSTEM_UI_FLAG_IMMERSIVE_STICKY hides the snack bar almost all the time, as described in the body of the question, no matter how or where users click.
While the 3rd full screen mode, without either flag, the lean back mode (GoogleDoc), responds to users with valid snack bars, only from the 2nd click. The 1st click from users is consumed as return from lean back mode, by displaying the status bar and navigation bar of the SystemUI.

So a quick solution to this problem for now is to disable either immersive flag. But I am not satisfied with this. Will keep looking for better answers.

What's more, I tried solutions on Stackoverflow, either by setting up a proper z-index, or LayoutParam, none of which achieves what I want: to display a snack bar on top of the immersive (sticky) full screen.

Update 20191102: Snack bars are not considered as appropriate means to display too many texts, nor is an icon recommended, according to the Material Design Guidelines. The proper UI component I should rely on is Bottom Sheet.

Leon
  • 811
  • 10
  • 21