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 the dialog. I thought: great! there is a function for this: setCanceledOnTouchOutside(boolean). But i has no effect. It simply doesn't work. I also tried to add an onTouchListener and listen for events that are outside the dialog, but those events doesn't seem to be captured by the listener :(
Any ideas why this doesn't work or how it could be done in another way?
Here is how i declare the Dialog:
mMenuDialog = new Dialog(this,
android.R.style.Theme_Translucent_NoTitleBar);
mMenuDialog.setContentView(R.layout.menu_dialog);
mMenuDialog.setCancelable(true);
mMenuDialog.setCanceledOnTouchOutside(true);
and here is the declaration of the custom view
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="300dp" android:layout_height="300dp"
android:background="@drawable/menu_dialog_background"
android:orientation="vertical" android:layout_gravity="center"
android:id="@+id/dialog_root">
...
</LinearLayout>
and here is the used background:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<padding android:left="15dp" android:top="15dp" android:right="15dp"
android:bottom="15dp" />
<solid android:color="#f0f0f0" />
<corners android:radius="15dip" />
</shape>