
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的正按钮?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)