到目前为止,我在搜索中看到了两种方法,这两种方法都遇到了麻烦.
方法1)
Settings.System.putInt(getContentResolver(), Settings.System.SCREEN_BRIGHTNESS, 100);
Run Code Online (Sandbox Code Playgroud)
方法2)
IHardwareService hardware = IHardwareService.Stub.asInterface(ServiceManager.getService("hardware"));
hardware.setScreenBacklight(.5);
Run Code Online (Sandbox Code Playgroud)
以下哪种方法是正确的?还是我应该使用另一个?
谢谢
我使用下面的代码来做同样的事情
WindowManager.LayoutParams WMLP = getWindow().getAttributes();
WMLP.screenBrightness = 0.15F;
getWindow().setAttributes(WMLP);
Run Code Online (Sandbox Code Playgroud)
使用上述代码的优点是,这仅在调用它的活动中影响屏幕亮度.因此,当我转移到某个其他活动(或)退出应用程序时,将恢复手机的默认亮度(由用户设置).
编辑:我忘了提到screenBrightness属性的范围是0.0 - 1.0
| 归档时间: |
|
| 查看次数: |
1668 次 |
| 最近记录: |