Sam-In-TechValens
Sam-In-TechValens

Reputation: 2519

text is not visible in the AlertDialog in Android?

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

Upvotes: 0

Views: 1447

Answers (3)

TNR
TNR

Reputation: 5869

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

Upvotes: 0

Chatura Dilan
Chatura Dilan

Reputation: 1572

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

Upvotes: 1

Malek Hijazi
Malek Hijazi

Reputation: 4162

You could directly call: adb.show();

Upvotes: 0

Related Questions