警报消息未显示在警告对话框中?

时间:2012-05-03 13:15:11

标签: android android-layout dialog alertdialog

我想将警告对话框显示到设备屏幕大小。我通过这个链接得到了解决方案How to make an 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);

如何设置信息,以便它能在对话窗口中正确显示?

提前致谢 普什帕

2 个答案:

答案 0 :(得分:1)

通过默认工具,您无法设置文字大小。你可以做一件简单的事。 wirte XML并将该XML扩展并传递给构建器视图。

   builder.setView(view)  

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

答案 1 :(得分:0)

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

 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);