在Android中的整个应用程序中永久禁用按钮 [英] disable buttons permanently throughout the aplication in android

查看:52
本文介绍了在Android中的整个应用程序中永久禁用按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

实际上我有3个按钮.用户应单击任意一个按钮,然后所有3个按钮应在整个应用程序中永久禁用(当我们关闭并打开应用程序时,按钮应处于禁用状态).我该如何实现?

Actually i have 3 buttons.User should click on any one button then all the 3 buttons should disable permanently throughout the app(when we close and open the app, buttons should be in disable state).How can i achieve this?

谢谢.

推荐答案

在SharePreferences中定义行为:

define the behavior in SharePreferences:

例如,在 onResume 中使用它:

SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context);
boolean enabled = pref.getBoolean("isEnabled",true);
myButton.setEnabled(enabled);

在按钮的 onClick 事件中

执行以下操作:

in onClick event of the button do this:

SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context);
pref.edit().putBoolean("isEnabled",false).commit();
myButton.setEnabled(false);

这篇关于在Android中的整个应用程序中永久禁用按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆