1
我想通过单击按钮来调整屏幕亮度,所以当背景为白色时,屏幕亮度应该最大,同时如果背景为黑色,则屏幕亮度应该最小,但是出现错误:NullPointerException ... 这里是我的代码:如何设置屏幕亮度?
public void lamp2(boolean mode){
if(mode){
r.setBackgroundColor(Color.WHITE);
btn.setText("Turn OFF");
btn.setTextColor(Color.RED);
WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.screenBrightness = 90/100.0f;
getWindow().setAttributes(lp);
this.mode = true;
}
else if(!mode){
r.setBackgroundColor(Color.BLACK);
btn.setText("Turn ON");
btn.setTextColor(Color.GREEN);
WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.screenBrightness = 100/100.0f;
getWindow().setAttributes(lp);
this.mode = false;
}
}
你在哪里得到* NullPointerException *? –
@MatejSpili我解决了这个问题,但我怎样才能获得最大的亮度和最低? –