简体   繁体   中英

Set Android screen brightness

I am trying to set the screen brightness in android completely dark. The first time it works perfectly but after the brightness is 0 but I can see the screen. How make the android screen completely dark?

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 . 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.)

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>) . 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. They have backlighting. Since you have 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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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