SilverBlue
SilverBlue

Reputation: 269

How to disable back button in all dialogs and layouts?

In my code:

@Override
public void onBackPressed() {
}

It works fine, but if I call a dialog, for example

final Dialog dialogPopupGewonnen = new Dialog(Start.this, android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);
dialogPopup.setContentView(R.layout.popup);

I can use the back button (the back button close the dialog popup). But I want to disable the back button in all layouts and dialogs.

Upvotes: 0

Views: 410

Answers (1)

alireza
alireza

Reputation: 524

You should override onBackPressed in all of your activities and for Dialog you can use setCancelable(false) like:

final Dialog dialogPopupGewonnen = new Dialog(Start.this, android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);
dialogPopup.setContentView(R.layout.popup);
dialogPopup.setCancelable(false);

Upvotes: 1

Related Questions