4

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);
Steve Robbins
  • 13,672
  • 12
  • 76
  • 124
jcesarms15
  • 181
  • 1
  • 3
  • 10

2 Answers2

4

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.

Cat
  • 66,919
  • 24
  • 133
  • 141
  • 1
    +1 for a great answer which seems to agree with [this answer](http://stackoverflow.com/a/6877820/2930186). The following is a nice related trick: http://stackoverflow.com/a/14280273/2930186 – ripopenid Nov 01 '13 at 02:11
1

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!

nhahtdh
  • 55,989
  • 15
  • 126
  • 162
trumpetlicks
  • 7,033
  • 2
  • 19
  • 33