How can I get a Dialog style activity window to fill the screen? How can I get a Dialog style activity window to fill the screen? android android

How can I get a Dialog style activity window to fill the screen?


I found the solution:

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

@Overridepublic void onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    setContentView(R.layout.your_layout);    getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);}

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


You may add this values to your style android:windowMinWidthMajor and android:windowMinWidthMinor

<style name="Theme_Dialog" parent="android:Theme.Holo.Dialog">    ...    <item name="android:windowMinWidthMajor">97%</item>    <item name="android:windowMinWidthMinor">97%</item></style>


I just want to fill only 80% of the screen for that I did like this below

        DisplayMetrics metrics = getResources().getDisplayMetrics();        int screenWidth = (int) (metrics.widthPixels * 0.80);        setContentView(R.layout.mylayout);        getWindow().setLayout(screenWidth, LayoutParams.WRAP_CONTENT); //set below the setContentview

it works only when I put the getwindow().setLayout... line below the setContentView(..)

thanks @Matthias