Overflow menu, press the shutdown button. Immersive Mode - Android 4.4 Kitkat

Does anyone know if this is a mistake or should do it. When you click on the overflow icon when using KitKat Immersive mode, it turns off dive mode. Anyone else come across this?

Full Code from Google - Here

public void toggleHideyBar() { // The UI options currently enabled are represented by a bitfield. // getSystemUiVisibility() gives us that bitfield. int uiOptions = getActivity().getWindow().getDecorView().getSystemUiVisibility(); int newUiOptions = uiOptions; boolean isImmersiveModeEnabled = ((uiOptions | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) == uiOptions); if (isImmersiveModeEnabled) { Log.i(TAG, "Turning immersive mode mode off. "); } else { Log.i(TAG, "Turning immersive mode mode on."); } // Navigation bar hiding: Backwards compatible to ICS. if (Build.VERSION.SDK_INT >= 14) { newUiOptions ^= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; } // Status bar hiding: Backwards compatible to Jellybean if (Build.VERSION.SDK_INT >= 16) { newUiOptions ^= View.SYSTEM_UI_FLAG_FULLSCREEN; } // Immersive mode: Backward compatible to KitKat. // Note that this flag doesn't do anything by itself, it only augments the behavior // of HIDE_NAVIGATION and FLAG_FULLSCREEN. For the purposes of this sample // all three flags are being toggled together. // Note that there are two immersive mode UI flags, one of which is referred to as "sticky". // Sticky immersive mode differs in that it makes the navigation and status bars // semi-transparent, and the UI flag does not get cleared when the user interacts with // the screen. if (Build.VERSION.SDK_INT >= 18) { newUiOptions ^= View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY; } getActivity().getWindow().getDecorView().setSystemUiVisibility(newUiOptions); } 
+7
source share
4 answers

In K, the overflow menu is a separate window that focuses and, therefore, controls the current system user interface flags.

However, this only happens if you are trying to show the action bar when the status bar is hidden, which is discouraged . For context menus outside the action bar, you can use PopupWindow (using PopupWindow you can set the system interface flags yourself)).

+3
source

I do not understand how to set the system interface flags for PopupWindow. I tried something like this:

 PopupMenu popupMenu = new PopupMenu(mainHandle, view) { @Override public void show() { getWindow().getDecorView().setSystemUiVisibility( View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY); super.show(); } 
+2
source

The following is a workaround in Kotlin that allows you to enable dive mode when the ActionBar popup menu is rejected:

 override fun onCreate(savedInstanceState: Bundle?) { ... supportActionBar!!.addOnMenuVisibilityListener { isVisible -> if (!isVisible) enableImmersiveMode() } ... } @SuppressLint("InlinedApi") private fun enableImmersiveMode() { window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN) window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION or View.SYSTEM_UI_FLAG_FULLSCREEN or View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION } 
0
source

Something that worked well for me - I hope this helps those who come back to this in the future.

You can use the Handler to change flags after the overflow menu appears. On my devices, the back button is still displayed, but the black navigation bar is not visible (disappears before it appears visually).

 // Creates the PopupMenu. PopupMenu popup = new PopupMenu(getContext(), view) { @Override public void show() { // Shows the menu. super.show(); // Sets the UI flags to prevent weird changing of window. Handler temp = new Handler(); temp.postDelayed(new Runnable() { @Override public void run() { getWindow().getDecorView().setSystemUiVisibility( View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY); } }, 50); } } 
0
source

Source: https://habr.com/ru/post/959297/


All Articles