注意点 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
}
}

最新文章

  1. 常用git命令纪录
  2. Arcgis10.2 破解注意问题
  3. CS0016: 未能写入输出文件的解决方法
  4. Hadoop 系列 - (1) - 学习随笔 - 起源、构成
  5. BZOJ2318: Spoj4060 game with probability Problem
  6. 【.net 深呼吸】细说CodeDom(10):生成异常处理语句
  7. android studio 环境变量配置
  8. mybatis_helloWorld_sequence图(3)
  9. oracle、导出、导入
  10. 数据结构之并查集Union-Find Sets
  11. UnderWater+SDN论文之五
  12. 前端基础-- CSS
  13. (转发)一个通用的C++ 消息总线框架
  14. jiffies存放
  15. HTTP API接口测试利器PostMan介绍
  16. java的object类函数详解
  17. Android开发规范——命名
  18. 自定义ajax,添加loading效果
  19. Python-调用系统指令小记
  20. python中range函数与列表中删除元素

热门文章

  1. LINUX文件目录存放文件说明
  2. 19 01 03 css 中 reset 模块 设置
  3. indy tcpclient tcpServer
  4. PAT A1009-1012
  5. Lambder笔记
  6. Python说文解字_计数器
  7. html分页自适应居中;css设置分页自适应居中
  8. Spring使用Rabbitmq (简单使用)
  9. ElasticSearch-The number of object passed must be even but was [1]-问题解决
  10. python编程:从入门到实践----第四章&gt;操作列表