views:

747

answers:

2

I am using an activity with the dialog theme set, and I want it to be full screen. I tried all sorts of things, even going through the WindowManager to expand the window to full width and height manually, but nothing works.

Apparently, a dialog window (or an activity with the dialog theme) will only expand according to its contents, but even that doesn't always work. For instance, I show a progress bar circle which has width and height set to FILL_PARENT (so does its layout container), but still, the dialog wraps around the much smaller progress bar instead of filling the screen.

There must be a way of displaying something small inside a dialog window but have it expand to full screen size without its content resizing as well?

A: 

Really? The layout the activity is instantiating, does it have a parent Relative or LinearLayout tag that is set to height and width of fill_parent? I've implemented a few activities with a dialog theme and never had a problem with it taking up the entire screen.

MattC
Yes, the activity has a LinearLayout set to FILL_PARENT for both width and height.
Matthias
+5  A: 

I found the solution:

In your activity which has the Theme.Dialog style set, do this:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.your_layout);

    getWindow().setLayout(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
}

It's important that you call Window.setLayout() after you call setContentView(), otherwise it won't work.

Matthias