5

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?

User_1191
  • 981
  • 2
  • 8
  • 24
Anchal
  • 96
  • 1
  • 7
  • use onWindowsFocuschanged to find whether spinner is opened or not and then if spinner is open then write the code to hide navigation bar... for more details follow the- [link](http://stackoverflow.com/questions/18447063/spinner-get-state-or-get-notified-when-opens) – sud Dec 09 '15 at 09:38
  • How to use Custom Spinner in my code . – Anchal Dec 09 '15 at 11:40
  • follow this link it will help you [link](http://stackoverflow.com/questions/16694786/how-to-customize-a-spinner-in-android) or google for custom spinner tutorial – sud Dec 09 '15 at 12:05
  • I have used that code only,but it is not working. – Anchal Dec 21 '15 at 12:18
  • I'm facing the same issue. @Anchal did you find a solution? – Chaitali Apr 13 '18 at 09:56

1 Answers1

3

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

In your activity's 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.

Mick Ashton
  • 356
  • 4
  • 15