【问题标题】:How to set layout params to edittext in dialog?如何在对话框中将布局参数设置为edittext?
【发布时间】:2017-01-10 00:42:31
【问题描述】:

我正在尝试将一些布局参数设置为对话框中的编辑文本,但它似乎没有效果。为什么?如何减小编辑文本的宽度?

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

【问题讨论】:

    标签: android dialog layoutparams


    【解决方案1】:

    您需要在dialog.show()之后设置布局参数并将布局参数更改为FrameLayout.LayoutParams

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多