android - 如何将布局参数设置为对话框中的编辑文本?

标签 android dialog layoutparams

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

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

最佳答案

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

关于android - 如何将布局参数设置为对话框中的编辑文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6391603/

相关文章:

android - Google Play Alpha 版本 - 如何测试应用内购买

c++ - 对话框操作中的断言错误

android - 使用 setLayoutParams() 但它不起作用

android - 如何在没有 Fragment 的 Activity 中创建弹出覆盖 View ?

android - 在 android 2.3.3、2.3.5 中来自 gcm 的注册 ID 为 null 但它不为 null 并且在 android 2.3.4、4.0.4 中工作

javascript - 在 jscript 中更改警报名称

jQuery 提交验证,最后有模式对话框?

java - Android:当我还在 View 上设置 layoutParams 时,在 View 上调用 setPadding() 不起作用

Android View 的getTop()、getLeft()、getX()、getY()、getWidth()、getHeight()方法

android - 需要在对话框中显示名称