4

I'm trying to set some layout params to an edittext in a dialog but it seems to have no effect. Why? How can I reduce the width of my edittext?

AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder = new AlertDialog.Builder(context);
final EditText input = new EditText(context);                    
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(20, LinearLayout.LayoutParams.WRAP_CONTENT);
lp.setMargins(10, 0, 10, 0);  
input.setLayoutParams(lp); 

builder.setView(input)
.setCancelable(false)                   
.setPositiveButton(res.getString(R.string.ok), new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog, int id) {
             //...   
    }
})
.setNegativeButton(res.getString(R.string.cancel), new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog, int id) {
        dialog.cancel();
    }
});
mavrosxristoforos
  • 3,573
  • 2
  • 25
  • 40
jul
  • 36,404
  • 64
  • 191
  • 318

1 Answers1

10

You need to set the layout params after the dialog.show() and change the layout params to FrameLayout.LayoutParams

EdChum
  • 376,765
  • 198
  • 813
  • 562
anonymous
  • 101
  • 1
  • 3