Width and Height AlertDialog AppCompat

My custome style for AlertDialog looks like this:

<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 to change the width and height because it is too big on my tablet. Any ideas?

Below code does not work correctly:

  <item name="windowMinWidthMajor">@dimen/abc_dialog_min_width_major</item> <item name="windowMinWidthMinor">@dimen/abc_dialog_min_width_minor</item> 
+3
android android-alertdialog
May 20 '15 at 8:16
source share
3 answers

If this is a settings dialog box, you can only set the height and width in the newly created XML file. but if you use AlertDialog.builder, use this.

 AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setView(layout); builder.setTitle("Title"); alertDialog = builder.create(); alertDialog.show(); alertDialog.getWindow().setLayout(600, 400); //Controlling width and height. 

And follow this . Hope this helps you.

+7
May 20 '15 at 9:01
source share

I managed to adjust the width like this:

 <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 that you can customize:

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

Attribute Information

windowFixedHeightMajor: Fixed height for the window along the main axis of the screen, that is, when in the portrait.

windowFixedHeightMinor: Fixed height for the window along the secondary axis of the screen, i.e. in the landscape.

windowFixedWidthMajor: The fixed width of the window along the main axis of the screen, i.e. in the landscape.

windowFixedWidthMinor: The fixed width of the window along the secondary axis of the screen, i.e. for portrait orientation.

+7
Oct 07 '16 at 0:23
source share

I found that the easiest way is to set the style in styles.xml and then install android: windowMinWidthMajor android: windowMinWidthMinor

 <style name="Testing.Dialog" parent="Theme.AppCompat.Light.Dialog.Alert"> <item name="android:windowMinWidthMajor">90%</item> <item name="android:windowMinWidthMinor">90%</item> </style> 
+2
Jan 4 '18 at 12:07
source share



All Articles