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 9204261
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:40:12+00:00 2026-06-17T23:40:12+00:00

I have this custom dialog inside an Activty which is inside ActivityGroup . I

  • 0

I have this custom dialog inside an Activty which is inside ActivityGroup.

I want the dialog to dismiss when clicked outside, and tried everything i found online to make it work..

I’ve tried the setCanceledOnTouchOutside(true) – didn’t work

I’ve tried:

public boolean onTouchEvent ( MotionEvent event ) {
  // I only care if the event is an UP action
  if ( event.getAction () == MotionEvent.ACTION_UP ) {
    // create a rect for storing the window rect
    Rect r = new Rect ( 0, 0, 0, 0 );
    // retrieve the windows rect

    this.getWindow ().getDecorView ().getHitRect ( r );
    Log.i(r.toShortString(),r.toShortString());
    // check if the event position is inside the window rect
    boolean intersects = r.contains ( (int) event.getX (), (int) event.getY () );
    // if the event is not inside then we can close the activity
    if ( !intersects ) {
      // close the activity
      this.dismiss ();
      // notify that we consumed this event
      return true;
    }
  }

and it didn’t work too..

as i see in the LogCat – i think that from some reason the dialog window size is full screened that why i have no “outside” to touch..

i think it might have to do something with the activity group.. any suggestions ?

  • 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-06-17T23:40:13+00:00Added an answer on June 17, 2026 at 11:40 pm

    Ok so after lots of thinking i found out the most simple solution:

    The Problem:

    From some reason – although the theme I’ve used is a dialog and not a full screen display – the getWindow().getDecorView() returns a View which covers the whole screen.

    The Solution:

    in my XML file I gave the root element an id and I’ve changed the function above as follow:

    private View rootView;
    
    public BaseDialog(Context context, int theme) {
        super(context, theme);  
        //I don't think the next 2 lines are really important - but I've added them for safety  
        setCancelable(true); 
        setCanceledOnTouchOutside(true);    
    }
    
    public void setRootView(int resourceId)
    {
        this.rootView = findViewById(resourceId);
    }
    
    @Override
    public boolean onTouchEvent(MotionEvent event) {
        Rect rect = new Rect();
        rootView.getHitRect(rect);
        if (!rect.contains((int)event.getX(), (int)event.getY()))
        {
            this.dismiss();
            return true;
        }
        return false;       
    }       
    

    Hope it will help someone… 🙂

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

Sidebar

Related Questions

I have a custom dialog which extends Dialog and has a ListView inside its
I have this custom JSlider, which will be used in many other forms/windows. But
I have used this custom grid view in my code, and I want to
I have this table, which can be seen as a basic custom gantt chart:
I have a ListView which contains custom rows. This custom row has following UI
I have a custom dialog in my android application. I want to have in
i have this code that should create a dialog with the page google inside
I have a standard jQuery UI dialog. Inside that dialog, I have a custom
Hi I have a JQuery Ui (jquery-ui-1.8.13.custom.min.js) inside a Dialog. When I start typing
I have a custom dialog inside public class NewPartnerDialog extends Dialog implements OnClickListener And

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.