要控制当前activity的亮度或者透明度,可以获取当前的窗口,设置其属性:
Window window = getWindow();
LayoutParams attributes = window.getAttributes();
attributes.screenBrightness = 0.5;
getWindow().setAttributes(attributes);
如果要调节系统的亮度,就需要把这个亮度值写到系统设置里去:
ContentResolver cr = getContentResolver();
//将亮度值写入settings
Settings.System.putInt(cr, "screen_brightness", iLightVal);
//从settings中读取亮度值
try {
int val = Settings.System.getInt(cr, "screen_brightness");
Log.d("screen_brightness", "current light val: "+val);
} catch (SettingNotFoundException e) {
e.printStackTrace();
Log.d("error", e.getMessage());
}
注意的地方:
1,sdk文档上有对screenBrightness这个参数的取值范围的描述,是0~1
2,对settings中写入的亮度值 0~255