I was able to set Immersive mode in my app that properly hides navigation
and status bars
in almost every case. The only exclusion I found so far is, that when I tap on a Spinner
component that has
android:spinnerMode="dropdown"
, the navigation bar
still comes up. It disappears after I select an item from the dropdown, but I want it to not show up at all. Is there a way I could do this?
I was able to fix this, although this didn't fit my needs well enough, it still prevents a window focus change, which is what causes the system UI to show up. Sorry it's in Kotlin
onCreate()
try {
val popup = Spinner::class.java.getDeclaredField("mPopup")
popup.isAccessible = true
// Get private mPopup member variable and try cast to ListPopupWindow
val popupWindow = popup.get(yourSpinnerView) as android.widget.ListPopupWindow
popupWindow.isModal = false
} catch (e: Throwable) {
// silently fail...
}
The important part is this line:
popupWindow.isModal = false
This doesn't affect the spinner interactions, at least for me it still registers clicks properly and hides when a tap occurs outside the popup. However, it doesn't capture all taps, so touching other screen elements will trigger their onClickListener
as well as hide the spinner. Because of that, I've decided to not use this method and just deal with the Nav bar appearing, since I couldn't get what I wanted by using this.
Hope this helps others, as it took me the better part of a week to figure this out. I wish Android didn't consider opening a spinner as a window visibility change, removing all window flags and killing immersive mode.
EDIT: Removed the custom class, opting for the simplest solution which is very easy to implement.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With