How to set undo false for activity when it opens as a dialog box?

Hi, I did n-activity in that I open the action as a Dialog popup for another action, SO I g. From a problem related to my theme,

<item `name="android:windowCloseOnTouchOutside">@bool/config_closeDialogWhenTouchOutside</item>` 

but I don’t know what value should I change inside the "windowCloseOnTouchOutside" so that I can make my activity dialog cancel false.? My code in the subject is as follows:

  <style name="Theme.Dialog"> <item name="android:windowFrame">@null</item> <item name="android:windowTitleStyle">@android:style/DialogWindowTitle</item> <item name="android:windowBackground">@android:drawable/panel_background</item> <item name="android:windowIsFloating">true</item> <item name="android:windowContentOverlay">@null</item> <item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item> <item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item> <item name="android:windowCloseOnTouchOutside">@bool/config_closeDialogWhenTouchOutside</item> <item name="android:windowActionModeOverlay">true</item> <item name="android:colorBackgroundCacheHint">@null</item> <item name="textAppearance">@android:style/TextAppearance</item> <item name="textAppearanceInverse">@android:style/TextAppearance.Inverse</item> <item name="textColorPrimary">@android:color/primary_text_dark</item> <item name="textColorSecondary">@android:color/secondary_text_dark</item> <item name="textColorTertiary">@android:color/tertiary_text_dark</item> <item name="textColorPrimaryInverse">@android:color/primary_text_light</item> <item name="textColorSecondaryInverse">@android:color/secondary_text_light</item> <item name="textColorTertiaryInverse">@android:color/tertiary_text_light</item> <item name="textColorPrimaryDisableOnly">@android:color/primary_text_dark_disable_only</item> <item name="textColorPrimaryInverseDisableOnly">@android:color/primary_text_light_disable_only</item> <item name="textColorPrimaryNoDisable">@android:color/primary_text_dark_nodisable</item> <item name="textColorSecondaryNoDisable">@android:color/secondary_text_dark_nodisable</item> <item name="textColorPrimaryInverseNoDisable">@android:color/primary_text_light_nodisable</item> <item name="textColorSecondaryInverseNoDisable">@android:color/secondary_text_light_nodisable</item> <item name="textColorHint">@android:color/hint_foreground_dark</item> <item name="textColorHintInverse">@android:color/hint_foreground_light</item> <item name="textColorSearchUrl">@android:color/search_url_text</item> <item name="textAppearanceLarge">@android:style/TextAppearance.Large</item> <item name="textAppearanceMedium">@android:style/TextAppearance.Medium</item> <item name="textAppearanceSmall">@android:style/TextAppearance.Small</item> <item name="textAppearanceLargeInverse">@android:style/TextAppearance.Large.Inverse</item> <item name="textAppearanceMediumInverse">@android:style/TextAppearance.Medium.Inverse</item> <item name="textAppearanceSmallInverse">@android:style/TextAppearance.Small.Inverse</item> <item name="listPreferredItemPaddingLeft">10dip</item> <item name="listPreferredItemPaddingRight">10dip</item> <item name="listPreferredItemPaddingStart">10dip</item> <item name="listPreferredItemPaddingEnd">10dip</item> <item name="preferencePanelStyle">@style/PreferencePanel.Dialog</item> </style> 
+6
source share
3 answers

You can do this in Java coding very easily. If you have an Activity (even if it looks like a Dialog) , you should do

 this.setFinishOnTouchOutside(false); 

if you used the Dialog class you should call

 dialog.setFinishOnTouchOutside(false) 

if you want to prevent it from closing when you click on background activity.

+31
source

This can help you. This is a way to handle an external touch event:

How to cancel a dialog, for example, "Activity" when it is touched outside the window?

There is a way to get the “touch external to cancel” dialog behavior from the Activity theme in the dialog box, although I have not fully studied whether it has unwanted side effects.

As part of your onCreate() action, before creating a view, you must set two checkboxes in the window: one to make it “non-modal”, to allow views other than your types of activity to receive events. The second way is to receive a notification that one of these events has occurred, which will send you the ACTION_OUTSIDE move ACTION_OUTSIDE .

Try the following:

 public class MyActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Make us non-modal, so that others can receive touch events. getWindow().setFlags(LayoutParams.FLAG_NOT_TOUCH_MODAL, LayoutParams.FLAG_NOT_TOUCH_MODAL); // ...but notify us that it happened. getWindow().setFlags(LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH, LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH); // Note that flag changes must happen *before* the content view is set. setContentView(R.layout.my_dialog_view); } @Override public boolean onTouchEvent(MotionEvent event) { // If we've received a touch notification that the user has touched // outside the app, finish the activity. if (MotionEvent.ACTION_OUTSIDE == event.getAction()) { finish(); return true; } // Delegate everything else to Activity. return super.onTouchEvent(event); } } 
+1
source

The best way is this code:

 AlertDialog.Builder alert = new AlertDialog.Builder(Activity.this); alert.setCancelable(false); 
0
source

Source: https://habr.com/ru/post/955389/


All Articles