How to set percentage width for dialog action

I have an Activity with a dialog theme ( Theme.Holo.DialogWhenLarge). It seems too narrow, and I would like it to fill a larger percentage of the screen. I am trying to accomplish this by overriding windowMinWidthMinor and windowMinWidthMajor .

The theme used by my activity is as follows:

<style name="MyTheme" parent="@android:style/Theme.Holo.DialogWhenLarge">
    <item name="android:windowMinWidthMajor">90%</item>
    <item name="android:windowMinWidthMinor">90%</item>
</style>

However, it seems that windowMinWidthMajor, and windowMinWidthMinordo not act. Can anyone explain what I'm doing wrong?

+5
source share
2 answers
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //Some code here
        setWindowHeight(90);
    }
    /**
     * Set percentage width height
     * @param percent percent from current size. From 0 to 100.
     */
    private void setWindowHeight(int percent){
        DisplayMetrics metrics = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(metrics);
        int screenHeight = metrics.heightPixels;
        WindowManager.LayoutParams params = getWindow().getAttributes();
        params.height = (int)(screenHeight*percent/100);
        this.getWindow().setAttributes(params);
    }
+3
source

android, . , , , , (: , - 40% , * 0,4)

-1

All Articles