'Immersive fullscreen and Preference Dialogs pulling down status bar
I'm using an immersive fullscreen activity and for my dialogs I used the hack I found here where I set the dialog not focusable when opening it so its not pulling down the status bar.
dialog.window?.setFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)
Now I'm looking for a way to get the same result for preference dialogs (right now its only a ListPreference)
I tried overriding onDisplayPreferenceDialog in my PreferenceFragment and set the flag on the dialog but the status bar is still showing up.
Solution 1:[1]
You can override onDisplayPreferenceDialog(preference: Preference?)
and create your own AlertDialog
The AlertDialog
supports radio buttons so actually you can create the same dialog which is presented from the preference library itself. When you show that dialog, you can apply the workaround fix for showing it in immersive mode.
override fun onDisplayPreferenceDialog(preference: Preference?) {
AlertDialog.Builder(context)
.setTitle(<titleResID>)
.setSingleChoiceItems(<itemsArrayResID>, 0) { dialog, which ->
(preference as ListPreference).value = this.resources.getStringArray(<valuesArrayResID>)[which]
dialog.dismiss()
}
.setPositiveButton(R.string.cancel) { _, _ -> }
.showImmersive()
}
Actually here I've created showImmersive()
extension method to the AlertDialog.Builder
using the workaround hack to show the alert dialogs in immersive mode
fun AlertDialog.Builder.showImmersive(): AlertDialog {
val alertDialog = create()
alertDialog.window?.setFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)
alertDialog.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_LAYOUT_FULLSCREEN or
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION or
View.SYSTEM_UI_FLAG_FULLSCREEN)
alertDialog.show()
alertDialog.window?.clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)
return alertDialog
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Dharman |