我正在尝试设置一个复选框来控制亮度。到目前为止,能够识别是否启用了自动亮度,但无法将其关闭或根据是否启用来关闭。我写了这段代码:
private static final String SCREEN_BRIGHTNESS_MODE = "Settings.System.SCREEN_BRIGHTNESS_MODE";
private static final int SCREEN_BRIGHTNESS_MODE_MANUAL = 0;
private static final int SCREEN_BRIGHTNESS_MODE_AUTOMATIC = 1;
try {
enabled = Settings.System.getInt(contentResolver, Settings.System.SCREEN_BRIGHTNESS_MODE);
} catch (SettingNotFoundException e1) {
// TODO Auto-generated catch block
enabled = 0;
e1.printStackTrace();
}
if(enabled==SCREEN_BRIGHTNESS_MODE_MANUAL) {
((CheckBox)auto).setChecked(false);
brightbar.setEnabled(true);
}
else if(enabled==SCREEN_BRIGHTNESS_MODE_AUTOMATIC) {
((CheckBox)auto).setChecked(true);
brightbar.setEnabled(false);
}
auto.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(enabled==SCREEN_BRIGHTNESS_MODE_MANUAL){
Settings.System.putInt(contentResolver, SCREEN_BRIGHTNESS_MODE, SCREEN_BRIGHTNESS_MODE_AUTOMATIC);
brightbar.setEnabled(false);
}else if(enabled==SCREEN_BRIGHTNESS_MODE_AUTOMATIC){
Settings.System.putInt(contentResolver, SCREEN_BRIGHTNESS_MODE, SCREEN_BRIGHTNESS_MODE_MANUAL);
brightbar.setEnabled(true);
}
}
});
如果活动模式自动识别它已打开,但如果我单击复选框以禁用它不起作用,从某种意义上说它将其关闭。相反,如果自动亮度被禁用,我点击复选框激活它,它就会起作用,因为它会激活它。