Skip to content Skip to sidebar Skip to footer

Alert Message Is Not Displaying In Alert Dialog Box?

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 th

Solution 1:

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

 AlertDialog.Builderbuilder=newAlertDialog.Builder(this);

    // Creates textviewTextViewtext=newTextView(this);  
    text.setText("Hello This text");  
    text.setLayoutParams(newLayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
    text.setTextSize(20);        
    text.setGravity(Gravity.CENTER);

    //Creates a linearlayout layout and sets it with initial paramsLinearLayoutll=newLinearLayout(this);
    ll.setLayoutParams(newLayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
    ll.setGravity(Gravity.CENTER);
    ll.addView(text);  //adds textview to llayout

    builder.setMessage("Title").setPositiveButton(
            "Ok", newDialogInterface.OnClickListener() {
                publicvoidonClick(DialogInterface dialog, int id) {
                    dialog.dismiss();
                }
            }); 

    Dialogd= builder.setView(ll).create();   

    //Fills up the entire Screen
    WindowManager.LayoutParamslp=newWindowManager.LayoutParams();
    lp.copyFrom(d.getWindow().getAttributes());
    lp.width = WindowManager.LayoutParams.FILL_PARENT;
    lp.height = WindowManager.LayoutParams.FILL_PARENT;
    d.show();
    d.getWindow().setAttributes(lp);

Solution 2:

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.

Post a Comment for "Alert Message Is Not Displaying In Alert Dialog Box?"