¿El mensaje de alerta no se muestra en el cuadro de diálogo de alerta?

I want to display the alert dialog box to device screen size. I got the solution through this link ¿Cómo hacer que un cuadro de diálogo de alerta ocupe el 90% del tamaño de la pantalla? 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?

Gracias de antemano Pushpa

preguntado el 03 de mayo de 12 a las 14:05

It's occupying almost 90% in my phone. What's the parent of the alert dialog you are calling from? . -

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. -

2 Respuestas

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

contestado el 03 de mayo de 12 a las 14:05

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? - empujador

@pushpa If it's working , consider accepting this as a solution. Let me check for that Orientation problem. - Niranjan

@ ngen: thanks, Dialog box is appearing on top window, even though gravity is center. how to make the dialog center. - empujador

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.

contestado el 03 de mayo de 12 a las 14:05

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. - empujador

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.