设为首页 加入收藏

TOP

调整Android手机屏幕亮度
2014-11-24 08:29:37 来源: 作者: 【 】 浏览:0
Tags:调整 Android 手机 屏幕 亮度

贴一段调整安卓手机屏幕亮度的代码 ,可以参考使用,见下:


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);


}


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Android范例animation代码片段 下一篇Android 4.1 无预览拍照

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·如何从内核协议栈到 (2025-12-27 03:19:09)
·什么是网络协议?有哪 (2025-12-27 03:19:06)
·TCP/ IP协议有哪些 (2025-12-27 03:19:03)
·怎样用 Python 写一 (2025-12-27 02:49:19)
·如何学习python数据 (2025-12-27 02:49:16)