Android 如何在对话框中将布局参数设置为edittext?

Android 如何在对话框中将布局参数设置为edittext?,android,dialog,layoutparams,Android,Dialog,Layoutparams,我试图在对话框中将一些布局参数设置为edittext,但似乎没有效果。为什么?如何减少编辑文本的宽度 AlertDialog.Builder builder = new AlertDialog.Builder(context); builder = new AlertDialog.Builder(context); final EditText input = new EditText(context); LinearLayout.LayoutParams

我试图在对话框中将一些布局参数设置为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();
    }
});

您需要在
对话框.show()之后设置布局参数,并将布局参数更改为
FrameLayout.layoutparms