其他分享
首页 > 其他分享> > Android 背光亮度设置

Android 背光亮度设置

作者:互联网

public static final int BRIGHTNESS_DIM = 20;
public static final int BRIGHTNESS_ON = 255;
private static final int MINIMUM_BACKLIGHT = BRIGHTNESS_DIM + 10;
private static final int MAXIMUM_BACKLIGHT = BRIGHTNESS_ON;
progress.setMax(MAXIMUM_BACKLIGHT); //总亮度范围
 
int nBacklight = MAXIMUM_BACKLIGHT;
try
{
 nBacklight = Settings.System.getInt(getContentResolver(), Settings.System.SCREEN_BRIGHTNESS);
}
catch(SettingNotFoundException e)
{
 e.printStackTrace();
} 
progress.setProgress(nBacklight);//显示当前亮度
 
//一定不能设置为0,否则会黑屏,且会立即进入休眠
Settings.System.putInt(getContentResolver(),Settings.System.SCREEN_BRIGHTNESS, nBacklight);
WindowManager.LayoutParams lpParam = getWindow().getAttributes();
lpParam.screenBrightness = Float.valueOf(nBacklight) * (1f / 255f);
getWindow().setAttributes(lpParam);      
progress.setProgress(nBacklight);

 

标签:BRIGHTNESS,int,nBacklight,System,static,设置,Android,光亮度,BACKLIGHT
来源: https://blog.51cto.com/u_15298588/3034409