问题描述
我看到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
这篇关于什么是正确的方式来调暗屏幕?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!