Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7066491
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:05:19+00:00 2026-05-28T05:05:19+00:00

am using a Dialog with a custom view. That view’s layout is 300dp x

  • 0

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> 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T05:05:19+00:00Added an answer on May 28, 2026 at 5:05 am

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using an AlertDialog that is very simple, just a custom view with
What I'm trying to archive: I want a dialog with a custom view in
I'm using a CMFCLinkCtrl in my custom dialog that inherits from CDialog. The CMFCLinkCtrl
I have created a custom dialog for Visual Studio Setup Project using the steps
I am using PopupManager in FB4 to display a custom dialog. popwin = new
I created a page that has a JQuery based dialog using the standard JQuery
Using jQuery's dialog I came across the following quirk (tested in FF3): User selects
I'm trying to create a DialogFragment using a custom view in an AlertDialog .
I'm using AsyncTask in my custom Dialog. AsyncTask works fine in activity, but inside
I'm working on creating a custom dialog to get input from the user. I've

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.