简体   繁体   English

设置Android屏幕亮度

[英]Set Android screen brightness

I am trying to set the screen brightness in android completely dark. 我试图将android中的屏幕亮度设置为完全黑暗。 The first time it works perfectly but after the brightness is 0 but I can see the screen. 第一次它完美地工作,但在亮度为0但我可以看到屏幕。 How make the android screen completely dark? 怎么让android屏幕完全黑暗?

This is my code: 这是我的代码:

WindowManager.LayoutParams params = 

    getWindow().getAttributes();
    params.flags |= LayoutParams.FLAG_KEEP_SCREEN_ON;
    params.screenBrightness = 0.0f;
    getWindow().setAttributes(params);

All screens have a minimum brightness without being completely off. 所有屏幕都具有最低亮度而不会完全关闭。 This is the setting 0.0f . 这是设置0.0f This is a hardware restriction and varies per phone; 这是硬件限制,因电话而异; there is no way to set a screen completely dark using the hardware. 使用硬件无法将屏幕设置为完全黑暗。 (You can remove backlighting, as @trumpetlicks's answer points out.) (你可以删除背光,正如@ trumpetlicks的答案指出的那样。)

If you are only trying to control the brightness for one app, you could use an AbsoluteLayout to contain your app, and place a View with 100% width, 100% height, overlayed on top of everything else, and set its background to rgba(0, 0, 0, <your alpha value>) . 如果您只是试图控制一个应用程序的亮度,可以使用AbsoluteLayout来包含您的应用程序,并放置一个宽度为100%,高度为100%的View ,覆盖其他所有内容,并将其背景设置为rgba(0, 0, 0, <your alpha value>) I think this is as close to dimming as you can get. 我认为这就像你能得到的那样接近调光。

If I understand your question correctly, you already have. 如果我理解你的问题,你已经有了。 What you are seeing is an artifact of almost all LCD type screens. 您所看到的是几乎所有LCD类型屏幕的神器。 They have backlighting. 他们有背光。 Since you have params.flags |= LayoutParams.FLAG_KEEP_SCREEN_ON; 既然你有params.flags |= LayoutParams.FLAG_KEEP_SCREEN_ON; , the screen (and it's backlights) are most certainly going to stay on, the actual pixel values being outputted are going to be black. 屏幕(以及它的背光)肯定会保持开启,输出的实际像素值将变为黑色。 This is an unfortunate property of LCDs is that their blacks are only SO black! 这是液晶显示器的一个不幸的属性,他们的黑人只是黑色!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM