I use this code to to hide the navigation bar:
View root = findViewById(android.R.id.content);
root.setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
But when a Spinner is touched, the status bar is shown on top of the screen.
This solution seems to work when android:spinnerMode="dropdown"
Field listPopupField = Spinner.class.getDeclaredField("mPopup");
listPopupField.setAccessible(true);
Object listPopup = listPopupField.get(spinner);
if (listPopup instanceof ListPopupWindow) {
Field popupField = ListPopupWindow.class.getDeclaredField("mPopup");
popupField.setAccessible(true);
Object popup = popupField.get((ListPopupWindow) listPopup);
if (popup instanceof PopupWindow) {
((PopupWindow) popup).setFocusable(false);
}
}
Is there a solution for android:spinnerMode="dialog" ?
You need to clear the focus every time you click the spinner as the popupWindow is recreated; but unfortunately there is no direct API for listening to this event.
To overcome this you can create a custom Spinner & override its
performClick()which gets triggered when the spinner is clicked to show up the menu. Then you can clear the focus as you shared.