3

I created a custom dialog that I'm dynamically putting views into via a RelativeLayout. Every time the dialog is displayed, it shows all my child views just great, but it has some space at the top that I can not account for. I'm assuming this is reserved for a "title" of the dialog (which I won't have). Is there a way to remove that space and have my custom dialog just wrap the contents that I'm putting in?

here is the xml for the layout:

<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content">
  <RelativeLayout
     android:id="@+id/handlay"
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" />  
</LinearLayout>

incidentally, I've tried just having the relative layout be the parent node, with the same results.

Here is the .java for the custom dialog.

public class HandResults extends Dialog implements DialogInterface {
    HandResults hr;
    Timer myTimer;
    RelativeLayout handrl;


    // constructor sets the layout view to handresult layout
    public HandResults(Context context) {
        super(context);
        setContentView(R.layout.handresults);
        hr = this;

    }

    // create a timer to remove the dialog after 3 seconds
    public void showHands(){
        this.show();
        myTimer = null;
        myTimer = new Timer();
        myTimer.schedule(new TimerTask() {
            @Override
            public void run() {
                hr.cancel(); 
            }
        }, 3000);

    }
}

and here is how I would call the dialog:

HandResults mhr = new HandResults(this);
mhr.showHands();

no matter what I do or how I change the layout file, I always have that buffer at the top, how can I get rid of that?

Kyle
  • 10,839
  • 17
  • 53
  • 63

1 Answers1

18

Put this code into class contstructor or onCreate() method:

    requestWindowFeature(Window.FEATURE_NO_TITLE);

It must be before calling setContentView method.

plugmind
  • 7,926
  • 4
  • 34
  • 39
  • This wasn't working for me, but here is a solution that worked for me: http://stackoverflow.com/a/1693716/445348 – cottonBallPaws Feb 01 '12 at 03:57
  • how can I write it inside an adapter .. I can't access the method – P-RAD Jul 25 '14 at 11:01
  • 2
    got it ! Dialog warningDialog; warningDialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE); – P-RAD Jul 25 '14 at 11:30
  • This didn't work for me because I was using AppCompatActivity, so I had to use `supportRequestWindowFeature(Window.FEATURE_NO_TITLE);` and that fixed it for me. – Carl Poole Mar 06 '17 at 21:26