Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AlertDialog AppCompat width and height

My custome style for AlertDialog look like:

<style name="Testing.Dialog" parent="Theme.AppCompat.Light.Dialog.Alert">
    <item name="colorAccent">@color/color_accent</item>
    <item name="android:textColorPrimary">@color/text_color_primary</item>
    <item name="android:background">@color/color_primary</item>
    <item name="android:windowIsFloating">true</item>
    <item name="android:windowContentOverlay">@null</item>
</style>

I need change width and height, because it is too large on my tablet. Any ideas?

Below code not working properly:

   <item name="windowMinWidthMajor">@dimen/abc_dialog_min_width_major</item>
   <item name="windowMinWidthMinor">@dimen/abc_dialog_min_width_minor</item>
like image 808
waclaw Avatar asked Nov 27 '22 10:11

waclaw


1 Answers

I was able to adjust the width like so:

<style name="NarrowDialog" parent="Theme.AppCompat.Light.Dialog.Alert">
    <item name="windowFixedWidthMajor">70%</item>
    <item name="windowFixedWidthMinor">70%</item>
</style>

Dialog dialog = new AlertDialog.Builder(this, R.style.NarrowDialog)...

There is also a minimum width you might wish to adjust:

<item name="windowMinWidthMajor">65%</item>
<item name="windowMinWidthMinor">65%</item>

Attribute details:

  • windowFixedHeightMajor:

A fixed height for the window along the major axis of the screen, that is, when in portrait.

  • windowFixedHeightMinor:

A fixed height for the window along the minor axis of the screen, that is, when in landscape.

  • windowFixedWidthMajor:

A fixed width for the window along the major axis of the screen, that is, when in landscape.

  • windowFixedWidthMinor:

A fixed width for the window along the minor axis of the screen, that is, when in portrait.

like image 95
Tim Malseed Avatar answered Dec 16 '22 02:12

Tim Malseed