Skip to content
This repository has been archived by the owner on Jul 13, 2020. It is now read-only.

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

Open
pasniak opened this issue Jun 5, 2019 · 1 comment
Open

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

pasniak opened this issue Jun 5, 2019 · 1 comment

Comments

@pasniak
Copy link

pasniak commented Jun 5, 2019

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
Copy link
Author

pasniak commented Jun 5, 2019

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?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant