am using a Dialog with a custom view. That view\'s layout is 300dp x 300dp is size and centered on the screen. Now i want it to be dismissed when the user touches outside th
i did solve it now by wrapping my custom dialog view layout with an additional LinearLayout and adding an onTouchListener to this wrapping LinearLayout. In that onTouchListener i checked if the click was inside or outside the dialog.
It might be a tad late but for those who are still looking for the answer, here it is.
Apply a custom style to your dialog. In your style, include this:
<item name="android:windowIsFloating">true</item>
Otherwise the dialog will use full screen. Hence no outside area to click to cancel. This works for dialogs with custom content.
Example:
<style name="dialog_theme" parent="@android:style/Theme.Dialog">
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowNoTitle">true</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_gravity">center</item>
</style>
Hope this helps.