anko icon indicating copy to clipboard operation
anko copied to clipboard

Alerts with no system bar, or: how to get dialog before show() ?

Open pasniak opened this issue 5 years ago • 1 comments

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)

pasniak avatar Jun 05 '19 11:06 pasniak

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?

pasniak avatar Jun 05 '19 12:06 pasniak