waclaw waclaw - 1 year ago 215
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>

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download