Skip to content

Snappy1

  • Home
  • Android
  • What
  • How
  • Is
  • Can
  • Does
  • Do
  • Why
  • Are
  • Who
  • Toggle search form

[FIXED] java – How to prevent touch when clicking on the background of the Android dialog

Posted on November 11, 2022 By

Solution 1 :

just add this line in onCreate method:

this.setFinishOnTouchOutside(false);

Solution 2 :

Remove the first line keep only dialog.setCancelable(false);

Solution 3 :

Use this code to prevent background touch such as dialogues.

getWindow().addFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);

Use this code to make the background touch impossible.

getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);

Thank you for your answers. Have a nice day!

Problem :

If we click the background of the dialog and click the back key, the dialog will not be canceled.

setCanceledOnTouchOutside(false);
setCancelable(false);

However, while the dialog is not canceled, there is a phenomenon that the click in the background in the buttons and the check box are clicked.

Is there a way to solve this problem?

Comments

Comment posted by Dreamer

Your question is not clear!!

Comment posted by Mouaad Abdelghafour AITALI

From your comment, your issue is when you open your dialog, the background (current activity) components are still clickable, right? Try to wrap all of them with a

Comment posted by user15043386

getWindow().addFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE); I solved it by putting this sentence in. Thank you for your reply.

Comment posted by user15043386

This code does not close the dialog, but the check box or button in the background is still clicked.

Comment posted by Mado

my bad, actually this is weird, can you provide the code in your main activity/fragments.

Comment posted by Mado

if the dialog is in activity or fragment, when the Alert dialog is popped up on screen, Activity/fragment will be onPuase() state the buttons should not be clickable till the dialog is dismissed.

Comment posted by user15043386

getWindow().addFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE); I solved it by putting this sentence in. Thank you for your reply.

READ  [FIXED] android - Hiding time in status bar
Powered by Inline Related Posts

Comment posted by Mado

great, thank you for sharing the solution, I would suggest you to add this answer in the answer section, maybe it will help someone, cheers lad!

Comment posted by user15043386

I think that sentence is a code that cannot be canceled when the back key is used. What I want is to block the click of a check box or button on the background of the dialog.

Android Tags:android, java, kotlin

Post navigation

Previous Post: [FIXED] android.media.ImageWriter produces green screen screen on every second posted Image frame
Next Post: [FIXED] android – Notifee native module not found

Related Posts

[FIXED] java – Android location service stop working when app destroyed or goes in background Android
[FIXED] react native – Using expo-speech in android doesn’t work and throw exception Android
[FIXED] android – Is it possible to show EmptyView after loader(ActivityIndicator) in CarouselView using Xamarin forms? Android
[FIXED] android – Create ArrayList where next element is bigger than previous by a certain number dynamically Android
[FIXED] java – how to add semi transparent overlay on imageview in android studio and show it properlay Android
[FIXED] java – Custom list preference dialog layout in Preference Screen, with custom list items Android

Archives

  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuándo
  • ¿Cuántas
  • ¿Cuánto
  • ¿Qué
  • Android
  • Are
  • At
  • C'est
  • Can
  • Comment
  • Did
  • Do
  • Does
  • Est-ce
  • Est-il
  • For
  • Has
  • Hat
  • How
  • In
  • Is
  • Ist
  • Kann
  • Où
  • Pourquoi
  • Quand
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welchen
  • Welcher
  • Welches
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Who's
  • Why
  • Wie
  • Will
  • Wird
  • Wo
  • Woher
  • you can create a selvedge edge: You can make the edges of garter stitch more smooth by slipping the first stitch of every row.2022-02-04
  • you really only need to know two patterns: garter stitch

Recent Posts

  • What is a good substitute for condensed milk?
  • ¿Como el cuerpo te avisa cuando te va a dar un infarto?
  • What is the luxury brand of Jaguar?
  • Who is Big poppa baseball player?
  • What material are foam runners?

Recent Comments

No comments to show.

Copyright © 2023 Snappy1.

Powered by PressBook Grid Dark theme