android– 如何在自定义对话框中创建正面和负面按钮

android– 如何在自定义对话框中创建正面和负面按钮,第1张

概述我想创建一个自定义对话框.所以我创建了一个模板’dialog_change’,然后打开对话框.DialogmyDialog=newDialog(Overview.this);myDialog.setContentView(R.layout.dialog_change);myDialog.setTitle("MyCustomDialogTitle");myDialog.show();现在我想在底部添加两个

我想创建一个自定义对话框.所以我创建了一个模板’dialog_change’,然后打开对话框.

Dialog myDialog = new Dialog(OvervIEw.this);myDialog.setContentVIEw(R.layout.dialog_change);myDialog.setTitle("My Custom Dialog Title");myDialog.show();

现在我想在底部添加两个按钮(一个正面和一个负面按钮).我怎样才能做到这一点?

解决方法:

我只是创建自己的自定义类来模拟AlertDialog,这样您就可以使用自己的布局而不附加任何字符串. (有一些奇怪的问题,如果你想要一个完全风格的AlertDialog你不能完全摆脱框架).这样的东西,但您可以根据需要完全展开:

public class CustomDialog extends Dialog {    private button positive, negative;    public CustomDialog(Context context) {        super(context);        initialize(context);    }    protected CustomDialog(Context context, boolean cancelable, OnCancelListener cancelListener) {        super(context, cancelable, cancelListener);        initialize(context);    }    public CustomDialog(Context context, int theme) {        super(context, theme);        initialize(context);    }    private voID initialize(Context c) {        //Inflate your layout, get a handle for the buttons        positive = (button)layout.findVIEwByID(R.ID.positive):        negative = (button)layout.findVIEwByID(R.ID.negative):        positive.setVisibility(VIEw.GONE);        negative.setVisibility(VIEw.GONE);    }    public voID setPositivebutton(String buttonText, VIEw.OnClickListener Listener) {        positive.setText(buttonText);        positive.setonClickListener(Listener);        positive.setVisibility(VIEw.VISIBLE);    }    public voID setNegativebutton(String buttonText, VIEw.OnClickListener Listener) {        negative.setText(buttonText);        negative.setonClickListener(Listener);        negative.setVisibility(VIEw.VISIBLE);    }}
总结

以上是内存溢出为你收集整理的android – 如何在自定义对话框中创建正面和负面按钮全部内容,希望文章能够帮你解决android – 如何在自定义对话框中创建正面和负面按钮所遇到的程序开发问题。

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

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

原文地址: https://outofmemory.cn/web/1110102.html

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

发表评论

登录后才能评论

评论列表(0条)

保存