i have an AlertDialog on my Android app. When i show to AlertDialog i want to disable only when users click "OKAY" button. Because i reset the screen when users clicked "OKAY" button.
My problem is when i click somewhere on screen outside of AlertDialog, dialog is closing but i can not clean the screen.
This is my code;
AlertDialog.Builder builder = new AlertDialog.Builder(GameOnePlayer.this, R.style.AlertDialogTheme);
//builder.setCancelable(true);
View view = LayoutInflater.from(GameOnePlayer.this).inflate(
R.layout.layout_winner_dialog,
(ConstraintLayout)findViewById(R.id.layoutAlertDialogContainer)
);
builder.setView(view);
final AlertDialog alertDialog = builder.create();
//alertDialog.setCanceledOnTouchOutside(false);
view.findViewById(R.id.buttonAlertDialog).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
hideSystemUI();
clearScreen();
alertDialog.dismiss();
}
});
if(alertDialog.getWindow() != null){
alertDialog.getWindow().setBackgroundDrawable(new ColorDrawable(0));
}
alertDialog.show();
I tried alertDialog.setCanceledOnTouchOutside(false); but it did'not work.
<style name="AlertDialogTheme" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item>
<item name="android:windowCloseOnTouchOutside">false</item>
</style>
This is my style.xml
What do I have to do for this? Thanks.
Edit: I tried these advices but did not work.
builder.setCancelable(false);
alertDialog.setCancelable(false);
alertDialog.setCanceledOnTouchOutside(false);
Edit2: Hi i found the solution on the other post. Just added these line in the onCreate method.
this.setFinishOnTouchOutside(false);
Many thanks for all you helpers.