public void SetBright(float value) { Window mywindow = getWindow(); WindowManager.LayoutParams lp = mywindow.getAttributes(); lp.screenBrightness = value; mywindow.setAttributes(lp);} 我想调整屏幕亮度.但是当我尝试使用这种方
public void SetBright(float value) { Window mywindow = getWindow(); WindowManager.LayoutParams lp = mywindow.getAttributes(); lp.screenBrightness = value; mywindow.setAttributes(lp); }
我想调整屏幕亮度.但是当我尝试使用这种方法时没有任何反应.可能是因为我使用KEEP_SCREEN_ON标志?
确保在设置屏幕亮度之前未启用“自动亮度”.如果您使用的是Android 2.2或更高版本的SDK,则可以在设置>显示或使用代码中手动执行此操作.就像是:
int brightnessMode = Settings.System.getInt(getContentResolver(), Settings.System.SCREEN_BRIGHTNESS_MODE); if (brightnessMode == Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC) { Settings.System.putInt(getContentResolver(), Settings.System.SCREEN_BRIGHTNESS_MODE, Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL); } WindowManager.LayoutParams layoutParams = getWindow().getAttributes(); layoutParams.screenBrightness = 0.5F; // set 50% brightness getWindow().setAttributes(layoutParams);
确保该值介于0.0F和1.0F之间.值-1.0F使用首选项中存储的默认亮度.根据文档“值小于0,默认值,意味着使用首选屏幕亮度.0到1调整亮度从暗到亮.”