歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> 調整Android手機屏幕亮度

調整Android手機屏幕亮度

日期:2017/3/1 10:02:36   编辑:Linux編程

貼一段調整安卓手機屏幕亮度的代碼 ,可以參考使用,見下:

public void setBrightness(int level) {
ContentResolver cr = getContentResolver();
Settings.System.putInt(cr, "screen_brightness", level);
try {
defaultLevel = Settings.System.getInt(cr, "screen_brightness");
} catch (SettingNotFoundException e) {
e.printStackTrace();
}
Window window = getWindow();
LayoutParams attributes = window.getAttributes();
float flevel = level;
attributes.screenBrightness = flevel / 255;
getWindow().setAttributes(attributes);
}

此外,UiModeManager這個類提供了控制系統UI模式的服務,可以參考使用:

{
UiModeManager uim = (UiModeManager) getSystemService(Context.UI_MODE_SERVICE);
int i = uim.getCurrentModeType();

if (i != Configuration.UI_MODE_TYPE_CAR) {
uim.enableCarMode(0);
}

uim.setNightMode(UiModeManager.MODE_NIGHT_YES);

}

Copyright © Linux教程網 All Rights Reserved