如何在android中启用和禁用对开关首选项的操作

时间:2015-05-09 06:51:45

标签: switchpreference

这不适用于切换首选项请帮助.......编写另一个代码..

SwitchPreference uiTestModePref = (SwitchPreference) findPreference("switch");
uiTestModePref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {    
    @Override
    public boolean onPreferenceChange(Preference preference, Object o) {
        boolean check = (preference).isEnabled();
        if (check) {
            android.provider.Settings.System.putInt(getContentResolver(),
            android.provider.Settings.System.HAPTIC_FEEDBACK_ENABLED, 1);
            Toast.makeText(getApplicationContext(), "Yes", Toast.LENGTH_LONG).show();
        }
        else {
            Toast.makeText(getApplicationContext(), "No", toast.LENGTH_LONG).show();
        }
        return false;
    }
});

1 个答案:

答案 0 :(得分:0)

应该是isChecked()而不是isEnabled()