SeekBar seekBar = (SeekBar) findViewById(R.id.seekBar);
// 进度条绑定最大亮度,255是最大亮度
seekBar.setMax(255);
// 取得当前亮度
int normal = Settings.System.getInt(getContentResolver(),
Settings.System.SCREEN_BRIGHTNESS, 255);
// 进度条绑定当前亮度
seekBar.setProgress(normal);
seekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
// 取得当前进度
int tmpInt = seekBar.getProgress();
// 当进度小于80时,设置成80,防止太黑看不见的后果。
if (tmpInt < 80) {
tmpInt = 80;
}
// 根据当前进度改变亮度
Settings.System.putInt(getContentResolver(),
Settings.System.SCREEN_BRIGHTNESS, tmpInt);
tmpInt = Settings.System.getInt(getContentResolver(),
Settings.System.SCREEN_BRIGHTNESS, -1);
youtParams wl = getWindow().getAttributes();
float tmpFloat = (float) tmpInt / 255;
if (tmpFloat > 0 && tmpFloat <= 1) {
wl.screenBrightness = tmpFloat;
}
getWindow().setAttributes(wl);
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
// TODO Auto-generated method stub
}
});