anko
anko copied to clipboard
Alerts with no system bar, or: how to get dialog before show() ?
I work on an immersive* activity. When I show an alert ctx.alert {....}
, the system bar re-appears. It would seem a hacky fix for this is to set the dialog to not focusable before showing it:
https://stackoverflow.com/questions/22794049/how-do-i-maintain-the-immersive-mode-in-dialogs/24549869#24549869
but AlertBuilder does not have any accessor to window...
How do I do this?
*) window.decorView.systemUiVisibility = (SYSTEM_UI_FLAG_LAYOUT_STABLE or SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION or SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or SYSTEM_UI_FLAG_HIDE_NAVIGATION or SYSTEM_UI_FLAG_FULLSCREEN or SYSTEM_UI_FLAG_IMMERSIVE_STICKY)
I have a solution which work in emulator but not on the phone....
Cast the builder:
val dialogInterface = builder?.build() as? AlertDialog
and call from activity:
fun Activity.showNoStatusBar(dialog: AlertDialog) {
dialog.window.setFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)
dialog.window.decorView.systemUiVisibility = window.decorView.systemUiVisibility
dialog.show()
dialog.window.clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)
}
Is there a better way?