开发者

How to set layout params to edittext in dialog?

开发者 https://www.devze.com 2023-03-13 15:31 出处:网络
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?

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);开发者_如何学Python
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();
    }
});


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

0

精彩评论

暂无评论...
验证码 换一张
取 消