What LayoutParams should be used in an AlertDialog?

I have a EditText object:

    EditText textbox = new EditText (this);
    textbox.setHint (something);

I want to add this view to an AlertDialog using the builder.

    AlertDialog.Builder builder = new AlertDialog.Builder (this);
    builder.setTitle (R.string.enter_password_name)
            .setPositiveButton (R.string.save_text, new DialogInterface.OnClickListener () {
                @Override
                public void onClick(DialogInterface dialog, int which) {

                }
            })
            .setNegativeButton (R.string.cancel_text, new DialogInterface.OnClickListener () {
                @Override
                public void onClick(DialogInterface dialog, int which) {

                }
            });

I know that there is a method setView(int) but I am using API 15 so I can only use setView(View), which is also a reason why I am creating the view by code.

So far so good, but I now need to set the LayoutParams of the view. What LayoutParams should I choose? I know that in a RelativeLayout you use a RelativeLayout.LayoutParams and in a LinearLayout you use a LinearLayout.LayoutParams. But what should I use in a dialog?

Answer

According to the source code here , alertdialog’s root element is a LinearLayout, so I would suggest using LinearLayout.LayoutParams

Leave a Reply

Your email address will not be published. Required fields are marked *