android – 如何在运行时禁用AlertDialog的正按钮?

android – 如何在运行时禁用AlertDialog的正按钮?,第1张

概述有没有办法在运行禁用AlertDialog的正按钮,比如在TextWatcher中? AlertDialog.Builder(this) .setTitle(getString(R.string.createvfs)) .setView(newVSView_v11) .setP @H_502_6@ 有没有办法在运行时禁用AlertDialog的正按钮,比如在TextWatcher中?

AlertDialog.Builder(this)                    .setTitle(getString(R.string.createvfs))                    .setVIEw(newVSVIEw_v11)                    .setPositivebutton(getString(R.string.okay),new DialogInterface.OnClickListener() {                                @OverrIDe                                public voID onClick(DialogInterface dialog,int whichbutton) {                                }                            })                    .setNegativebutton(getString(R.string.cancel),new DialogInterface.OnClickListener() {                                @OverrIDe                                public voID onClick(DialogInterface dialog,int whichbutton) {                                    // Canceled.                                }                            }).show();
解决方法 您需要获取对话框本身的引用以便稍后修改它,因此您必须稍微更改构建器,但随后您可以随时调用AlertDialog.getbutton()来启用或禁用该按钮.像这样……

//Use create() so you can get the instance backAlertDialog dialog = AlertDialog.Builder(this)                .setTitle(getString(R.string.createvfs))                .setVIEw(newVSVIEw_v11)                .setPositivebutton(getString(R.string.okay),new DialogInterface.OnClickListener() {                            @OverrIDe                            public voID onClick(DialogInterface dialog,int whichbutton) {                            }                        })                .setNegativebutton(getString(R.string.cancel),new DialogInterface.OnClickListener() {                            @OverrIDe                            public voID onClick(DialogInterface dialog,int whichbutton) {                                // Canceled.                            }                        }).create();//Then show itdialog.show();/* ...sometime in the distance future... */dialog.getbutton(DialogInterface.button_POSITIVE).setEnabled(false);

如果你想让按钮看不见,那就更难了.我现在无法测试是否在按钮上调用setVisibility()会产生良好的效果……

HTH

总结

以上是内存溢出为你收集整理的android – 如何在运行时禁用AlertDialog的正按钮?全部内容,希望文章能够帮你解决android – 如何在运行时禁用AlertDialog的正按钮?所遇到的程序开发问题。

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

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

原文地址:https://54852.com/web/1129715.html

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

发表评论

登录后才能评论

评论列表(0条)

    保存