什么是正确的方式来调暗屏幕?屏幕、正确、方式、来调暗

2023-09-05 04:56:44 作者:孤独总和

我看到2种方法至今在我的搜索,我有这两个麻烦。

I have seen 2 methods so far in my search, both of which I am having trouble with.

方法1)

Settings.System.putInt(getContentResolver(), Settings.System.SCREEN_BRIGHTNESS, 100);

方法2)

IHardwareService hardware = IHardwareService.Stub.asInterface(ServiceManager.getService("hardware"));
hardware.setScreenBacklight(.5);

哪个这些方法是正确的?还是有另一种,我应该用?

Which of these methods is correct? Or is there another that I should be using?

感谢

推荐答案

我用的是code以下做同样的

I use the code below to do the same

WindowManager.LayoutParams WMLP = getWindow().getAttributes();
WMLP.screenBrightness = 0.15F;
getWindow().setAttributes(WMLP);

使用上述code的优点是,这会影响屏幕的亮度仅在调用它的活性。所以,当我移动到其他一些活动(或)退出应用程序,手机的默认亮度(由用户设定)恢复正常。

The advantage of using the above code is that this affects the screen brightness only in the activity that calls it. So when I move to some other activity (or) quit the application, the phone's default brightness (As set by the user) is restored.

编辑: 我忘了提及的是,screenBrightness属性的范围为0.0 - 1.0

I forgot to mention that the range of the screenBrightness attribute is 0.0 - 1.0