首次启动时,我的应用将首选项设置为关于checkboxpreference的“true”。现在我需要以编程方式设置此值(android:enabled =“true”)或false。有什么想法吗?
protected void checkLicense(){
PackageManager manager = getPackageManager();
if (manager.checkSignatures("core.package.name", "key.package.name")
== PackageManager.SIGNATURE_MATCH) {
//full version
isEnabled = true;
Toast.makeText(this, "pro", Toast.LENGTH_LONG).show();
}
else {
Toast.makeText(this, "free", Toast.LENGTH_LONG).show();
isEnabled = false;
<CheckBoxPreference
android:enabled="true"
android:title="Now"
android:defaultValue="false"
android:key="keep" />
答案 0 :(得分:7)
启用CheckBox
getPreferenceScreen().findPreference("checkbox-preference-key").setEnabled(true); //Enabling
禁用CheckBox
getPreferenceScreen().findPreference("checkbox-preference-key").setEnabled(false);//Disabling