0

我正在使用必须在整个屏幕上显示的警报对话框,并且高度不会取决于文本的长度。但是我在显示文本时遇到了问题。我正在使用以下代码:

AlertDialog.Builder adb = new AlertDialog.Builder(getParent()); 
                WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
                lp.width = WindowManager.LayoutParams.FILL_PARENT;
                lp.height = WindowManager.LayoutParams.FILL_PARENT;
                adb.setTitle("Alert");  
                adb.setCancelable(true);  
                adb.setNeutralButton(android.R.string.ok,  
                        new DialogInterface.OnClickListener() {  
                    public void onClick(DialogInterface dialog, int whichButton){
                    }  
                }); 
                adb.setMessage(ConfigClass.MSG_USER_INFO_EMPOWEREDON);
                Dialog d = adb.setView(new View(this)).create();
                lp.copyFrom(d.getWindow().getAttributes());
                d.getWindow().setAttributes(lp);
                d.show();

请让我知道我错过了什么。 在此处输入图像描述

4

3 回答 3

1
AlertDialog alertDialog = new AlertDialog.Builder(this).create();
alertDialog.setTitle("Title");
alertDialog.setMessage("Are you ok?");
alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
   public void onClick(DialogInterface dialog, int which) {
      // here you can add ok click events
   }
});
alertDialog.setIcon(R.drawable.icon);
alertDialog.show();
于 2012-10-04T07:14:54.837 回答
0

您可以直接调用: adb.show();

于 2012-10-04T07:10:16.663 回答
0

您正在向 AlertDialog 添加新视图,因此无法再显示消息。我不理解您将 View 添加到 AlertDialog 的座右铭,但如果您的要求是这样,请添加一个 TextView 以向 View 显示消息,然后将 View 设置为 AlertDialog,如下所示。

TextView tv = new TextView(this);
tv.setText("your message");
View v = new View(this);
v.addView(tv);
alertDialog.setView(v);
于 2012-10-04T07:29:47.313 回答