如何控制机器人的宽度和默认警报对话框的高度? [英] how to control the width and height of default alert dialog in Android?

查看:94
本文介绍了如何控制机器人的宽度和默认警报对话框的高度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setTitle("Title");
            builder.setItems(items, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int item) {
                    Toast.makeText(getApplicationContext(), items[item], Toast.LENGTH_SHORT).show();
                }
            });
            AlertDialog alert = builder.create();

我使用上述code以示警告对话框,默认情况下它填补了宽度和WRAP_CONTENT高度屏幕。
如何控制默认的警告对话框的宽度和高度?
我试过了,alert.getWindow()的setLayout(100,100)。 //它不力的工作。
如何把布局PARAMS上的提示窗口,并手动设置宽度和高度?

I am using above code to show alert dialog , By default it fills the screen in width and wrap_content in height.
How to control the width and height of default alert dialog ?
I tried , alert.getWindow().setLayout(100,100); // It dint work.
How to get the layout params on the alert window and set manually the width and height ?

推荐答案

我不知道您是否可以更改AlertDialog的默认高度/宽度,但如果你想做到这一点,我想你可以通过创建自己的自定义做对话。你只需要给安卓主题=@安卓风格/ Theme.Dialog在android的manifest.xml为您的活动,可以写整个布局按照您的需求。您可以设置从Android资源XML自定义对话框的高度和宽度。

I dont know whether you can change the default height/width of AlertDialog but if you wanted to do this, I think you can do it by creating your own custom dialog. You just have to give android:theme="@android:style/Theme.Dialog" in the android manifest.xml for your activity and can write the whole layout as per your requirement. you can set the height and width of your custom dialog from the Android Resource XML.

这篇关于如何控制机器人的宽度和默认警报对话框的高度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆