AlertDialog AppCompat的宽度和高度 [英] AlertDialog AppCompat width and height
本文介绍了AlertDialog AppCompat的宽度和高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的AlertDialog自定义样式如下:
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>
推荐答案
如果是自定义对话框,则只能在新创建的XML文件中设置高度和宽度.但是,如果您使用的是AlertDialog.builder,请使用它.
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);
builder.setView(layout);
builder.setTitle("Title");
alertDialog = builder.create();
alertDialog.show();
alertDialog.getWindow().setLayout(600, 400); //Controlling width and height.
并遵循此希望它可能会帮助您.
And follow this Hope it may help you out.
这篇关于AlertDialog AppCompat的宽度和高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文