Android activity 亮度调整
2024-08-30 06:00:28
注意点 screenBrightness 取值范围0-1 不是0-255一定要注意
scanForActivity(context) 是根据上下文获取所在的activity
如果直接在activity 调用的话使用 this.window.attributes
/**
* 获取当前屏幕亮度
*/
fun getBrightness():Int {
val lp = scanForActivity(context)?.window?.attributes
if(lp != null){
//screenBrightness 默认为-1
if(lp.screenBrightness < 0) return 0
return (lp.screenBrightness * 255).toInt()
}
return 0
} /**
* 设置屏幕亮度
* @param brightness 取值范围 0-255
*/
fun setBrightness(brightness:Int){
val lp = scanForActivity(context)?.window?.attributes
if(lp != null){
lp.screenBrightness = brightness.toFloat() / 255
ChaoUtil.scanForActivity(context)?.window?.attributes = lp
}
}
最新文章
- 常用git命令纪录
- Arcgis10.2 破解注意问题
- CS0016: 未能写入输出文件的解决方法
- Hadoop 系列 - (1) - 学习随笔 - 起源、构成
- BZOJ2318: Spoj4060 game with probability Problem
- 【.net 深呼吸】细说CodeDom(10):生成异常处理语句
- android studio 环境变量配置
- mybatis_helloWorld_sequence图(3)
- oracle、导出、导入
- 数据结构之并查集Union-Find Sets
- UnderWater+SDN论文之五
- 前端基础-- CSS
- (转发)一个通用的C++ 消息总线框架
- jiffies存放
- HTTP API接口测试利器PostMan介绍
- java的object类函数详解
- Android开发规范——命名
- 自定义ajax,添加loading效果
- Python-调用系统指令小记
- python中range函数与列表中删除元素