1

我想向设备屏幕大小显示警报对话框。我通过此链接获得了解决方案How to make a alert dialog fill 90% of screen size? 我使用那里给出的解决方案,它工作得很好,但我的警报消息以非常小的尺寸显示。我们甚至无法以横向方式识别信息。我使用了以下代码。

AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(R.string.app_description).setPositiveButton(
                    "Ok", new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {
                            dialog.dismiss();
                        }
                    });
            builder.Title(title);

            Dialog d = builder.setView(new View(this)).create();
            WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
            lp.copyFrom(d.getWindow().getAttributes());
            lp.width = WindowManager.LayoutParams.FILL_PARENT;
            lp.height = WindowManager.LayoutParams.FILL_PARENT;
            d.show();
            d.getWindow().setAttributes(lp);

如何设置消息,使其正确显示在对话窗口中?

在此先感谢 Pushpa

4

2 回答 2

1

默认情况下,您无法设置文本大小。你可以做一件简单的事情。编写一个 XML 并扩展该 XML 并传递给构建器视图。

   builder.setView(view)  

除了您将视图设置为对话框之外,什么都没有。并且该视图将处理所有触摸。您可以在 xml 中指定视图的高度和宽度,包括文本大小。

于 2012-05-03T13:25:24.413 回答
1

检查此代码并告诉我这是否是您真正想要实现的目标?

 AlertDialog.Builder builder = new AlertDialog.Builder(this);

    // Creates textview
    TextView text = new TextView(this);  
    text.setText("Hello This text");  
    text.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
    text.setTextSize(20);        
    text.setGravity(Gravity.CENTER);

    //Creates a linearlayout layout and sets it with initial params
    LinearLayout ll = new LinearLayout(this);
    ll.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
    ll.setGravity(Gravity.CENTER);
    ll.addView(text);  //adds textview to llayout

    builder.setMessage("Title").setPositiveButton(
            "Ok", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    dialog.dismiss();
                }
            }); 

    Dialog d = builder.setView(ll).create();   

    //Fills up the entire Screen
    WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
    lp.copyFrom(d.getWindow().getAttributes());
    lp.width = WindowManager.LayoutParams.FILL_PARENT;
    lp.height = WindowManager.LayoutParams.FILL_PARENT;
    d.show();
    d.getWindow().setAttributes(lp);
于 2012-05-03T13:58:30.477 回答