I have an AlertDialog :
AlertDialog.Builder builder = new AlertDialog.Builder(context, AlertDialog.THEME_HOLO_LIGHT);
ListAdapter adapter = new CustomDialogAdapter(context, itemsList);
builder.setAdapter(adapter, listener);
builder.setTitle(title);
AlertDialog dialog = builder.create();
dialog.setCanceledOnTouchOutside(true);
setCanceledOnTouchOutside is working only when i tap on a certain distance from the dialog.When i tap just near the dialog it doesn't get dismissed.Do you guys know a way to dismiss the dialog even when i tap just near the dialog?Thanks.
setCancelable(false) means that back key doesn't close the dialog.
setCanceledOnTouchOutside only prevents dismissing by clicking outside of the dialog. But you can still dismiss it with back button for instance. If you don't want your dialog to be cancelable at all use dialog.setCancelable(false)
Using AlertDialog.THEME_HOLO_LIGHT works if you want the dialog to be full screen. An alternative is to create your own style, like so:
AlertDialog.Builder builder = new AlertDialog.Builder(context, R.style.ThemeDialogCustom);
ListAdapter adapter = new CustomDialogAdapter(context, itemsList);
builder.setAdapter(adapter, listener);
builder.setTitle(title);
AlertDialog dialog = builder.create();
dialog.setCanceledOnTouchOutside(true);
have style.xml in values folder like below:::
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="ThemeDialogCustom" parent="android:Theme.Dialog">
<item name="android:windowFrame">@null</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:windowBackground">@color/transparent_color</item>
<item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
<item name="android:colorBackgroundCacheHint">@null</item>
</style>
</resources>
also add colors.xml in values folder:::
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="transparent_color">#00000000</color>
</resources>
This is working for me. Hope it will works for you as well
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With