Android adjusts screen brightness

Source: Internet
Author: User

One: Only change the current program Android screen brightness
(1) Method:
Lp.screenbrightness value 0.0--1.0※ Set Value (float) range, default is less than 0 (system setting), 0.0 (dark) ~1.0 (bright) ※ Call processing place, for example, Activity.oncreate () and so on

Code:
Windowmanager.layoutparams LP = GetWindow (). GetAttributes ();

lp.screenbrightness = 1.0f;

GetWindow (). SetAttributes (LP);

Note: 1, B is a floating-point number from 0~1, indicating brightness

2, when we encounter the activity as a sub-activity into the tabactivity or ViewGroup class container, the above method is usually not successful.

In child activity, the screen brightness does not change.              Because the dimming scope changes, the brightness is changed before the activity.              The tabactivity or ViewGroup container is now modified as a child activity.          Therefore, the GetParent () method is required to obtain the parent and then set. 3.


(2) Recovery

When you leave the current acitivity, the brightness of the screen is restored to its original brightness. The lp.screenbrightness is also set to-1 (WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE), it also restores the screen to its original brightness (i.e. system settings).


(3) Minimum brightness

WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE, the official document says this value can set the screen brightness to the lowest brightness (Lowest brightness). The real sense is to set the screen to full black and the screen will not respond to touch. On G3 (CM6), setting the screen to the minimum brightness value is 0.004(accuracy 0.001), when the screen is basically all black, but still can control. Less than 0.004 (accuracy 0.001), the screen loses control. 0.01 is also a value to record, the screen brightness is low enough, when you can still see things. These values should be device-related and cannot be set in a random setting.

Android adjusts screen brightness

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.