waclaw waclaw - 6 months ago 89
Android Question

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>

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>


If it is a customizes dialog box then you can set the height and width in new created XML file only. but if you are using AlertDialog.builder then use this.

AlertDialog.Builder builder = new AlertDialog.Builder(this);
alertDialog = builder.create();
alertDialog.getWindow().setLayout(600, 400); //Controlling width and height.

And follow this Hope it may help you out.