android– 如何在对话框中将layout params设置为edittext?

android– 如何在对话框中将layout params设置为edittext?,第1张

概述我试图在对话框中为一个edittext设置一些布局参数,但它似乎没有任何效果.为什么?如何减小编辑文本的宽度?AlertDialog.Builderbuilder=newAlertDialog.Builder(context);builder=newAlertDialog.Builder(context);finalEditTextinput=newEditText(context);

我试图在对话框中为一个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();    }});

解决方法:

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

总结

以上是内存溢出为你收集整理的android – 如何在对话框中将layout params设置为edittext?全部内容,希望文章能够帮你解决android – 如何在对话框中将layout params设置为edittext?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1115370.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-29
下一篇 2022-05-29

发表评论

登录后才能评论

评论列表(0条)

保存