0

I am using a Alert dialog that must be shown on the whole screen, and the height will not depends on the length of text. But I am getting problem in showing text. I am using the below code:

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

Please let me know what I am missing. enter image description here

Sam-In-TechValens
  • 2,501
  • 4
  • 34
  • 67

3 Answers3

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();
Chatura Dilan
  • 1,502
  • 1
  • 16
  • 29
0

You could directly call: adb.show();

Malek Hijazi
  • 4,112
  • 1
  • 26
  • 31
0

You are adding new View to the AlertDialog so Message cannot be displayed anymore. I am not understanding your motto in adding View to AlertDialog but if your requirement is so then add a TextView to display message to the View and then set the View to AlertDialog as below.

TextView tv = new TextView(this);
tv.setText("your message");
View v = new View(this);
v.addView(tv);
alertDialog.setView(v);
TNR
  • 5,839
  • 3
  • 33
  • 62