1

这不适用于开关首选项,请帮助.......编写另一个代码..

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;
    }
});
4

1 回答 1

0

它应该isChecked()代替isEnabled()

于 2016-05-19T05:25:22.327 回答