14

I want to set up a proper style for my ProgressDialog. I like the default one but I want to customize it. I've tried to use AppCompat dialogs but they all setup some weird width and height for my Dialog.

I found that extending from MaterialDialog do the trick, so this code works:

<style name="ProgressDialogTheme" parent="MaterialBaseTheme.AlertDialog" >
</style>

This is because MeterialDialog itself setup custom width

<style name="MaterialBaseTheme.AlertDialog" parent="MaterialBaseTheme.Dialog">
        <item name="android:windowMinWidthMajor">@android:dimen/dialog_min_width_major</item>
        <item name="android:windowMinWidthMinor">@android:dimen/dialog_min_width_minor</item>
    </style>

And I found that there is AppCompat dialog that set up the same custom width, here it is:

<style name="Base.Theme.AppCompat.Light.Dialog.Alert">
        <item name="windowMinWidthMajor">@dimen/abc_dialog_min_width_major</item>
        <item name="windowMinWidthMinor">@dimen/abc_dialog_min_width_minor</item>
    </style>

but it do not work

The only difference is a andorid namespace at the beginning of MeterialDialog attribute.

Can someone explain why android:windowMinWidthMajor do the trick?

nutella_eater
  • 3,393
  • 3
  • 27
  • 46

3 Answers3

20

According to this link:

Min_witdh_major is:

The platform's desired minimum size for a dialog's width when it is along the major axis (that is the screen is landscape). This may be either a fraction or a dimension.

And min_with_minor is:

The platform's desired minimum size for a dialog's width when it is along the minor axis (that is the screen is portrait). This may be either a fraction or a dimension.

In appcompat, this value is set as 65%.

Ian Wong
  • 1,617
  • 14
  • 11
9

@Ian Wong's answer is correct. Below are further details on that:

android:windowMinWidthMajor -> min_dialog_width in Landscape

android:windowMinWidthMinor -> min_dialog_width in Portrait

  • The height of the dialog however isn't set and just wraps the content.

The actual values for @dimen/abc_dialog_min_width_major & @dimen/abc_dialog_min_width_minor is defined in the following path:

location of actual values defined for the dimensions

@dimen/abc_dialog_min_width_major - is 65% to 45% depending on the screen size. @dimen/abc_dialog_min_width_minor - is 95% to 72% depending on the screen size.

stkent
  • 19,772
  • 14
  • 85
  • 111
theThapa
  • 581
  • 4
  • 11
0

See also the original docs that introduced the values in Api 11:

windowMinWidthMajor

The minimum width the window is allowed to be, along the major axis of the screen. That is, when in landscape. Can be either an absolute dimension or a fraction of the screen size in that dimension.

May be a dimension value, which is a floating point number appended with a unit such as "14.5sp". Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), and mm (millimeters).

May be a fractional value, which is a floating point number appended with either % or %p, such as "14.5%". The % suffix always means a percentage of the base size; the optional %p suffix provides a size relative to some parent container.

Constant Value: 16843606 (0x01010356)

And similarly for windowMinWidthMinor ("That is, when in portrait.").

qix
  • 7,228
  • 1
  • 55
  • 65