如何控制机器人的宽度和默认警报对话框的高度?警报、对话框、宽度、机器人

由网友(恰好心动)分享简介:AlertDialog.Builder builder = new AlertDialog.Builder(this);builder.setTitle("Title");builder.setItems(items, new DialogInterface.OnClickListener() {public voi...

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.

阅读全文

相关推荐

最新文章