Reputation: 2519
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.
Upvotes: 0
Views: 1447
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
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