1

I want to display the alert dialog box to device screen size. I got the solution through this link How to make an alert dialog fill 90% of screen size? I use the solution given there, it works just fine but my alert message is displaying in very small size. we can't even make out the message in landscape orientation. I have used the following code.

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

How to set the message, so that it will properly display in the dialog window?

Thanks in advance Pushpa

Community
  • 1
  • 1
pushpa
  • 573
  • 2
  • 7
  • 19
  • It's occupying almost 90% in my phone. What's the parent of the alert dialog you are calling from? . – NT_ May 03 '12 at 13:20
  • Ok button is just proper i.e it is at the bottom of the window. only thing is am not getting message which set to builder class. – pushpa May 03 '12 at 13:28

2 Answers2

1

By the default implement-ion you can't set the text size. you can do one simple thing. wirte a XML and inflate that XML and pass to builder view.

   builder.setView(view)  

nothing but you are setting a view to dialog. and that view will handle all the touches. and you can specify height and width of the views in xml including text size.

santhu
  • 68
  • 8
  • Thanks santhu, This works good. But the thing is if device orientation changes, when the dialog is in front, we should press ok button twice (as many times our orientation changed) to dismiss the dialog. – pushpa May 04 '12 at 05:49
1

Check this code and tell me if that's what you really wanted to achieve ?.

 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);
NT_
  • 2,216
  • 1
  • 18
  • 23
  • Thank you very much. This works for good. But what i observe is , If device orientation changes when the dialog is in the front, I have to press ok button twice to dismiss the dialog. How to avoid this? – pushpa May 04 '12 at 05:18
  • @pushpa If it's working , consider accepting this as a solution. Let me check for that Orientation problem. – NT_ May 04 '12 at 10:21
  • @ ngen: thanks, Dialog box is appearing on top window, even though gravity is center. how to make the dialog center. – pushpa May 04 '12 at 10:25