问题
I would like to increase the brightness of the screen using a seek bar within my Android application, but I'm not sure how to do this. How can I add this functionality?
回答1:
Using this you can set the screen brightness:
WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.screenBrightness = 100 / 100.0f;
getWindow().setAttributes(lp);
Now, as you want to implement progress bar like control, i would suggest you to implement SeekBar, so using this you can easily increase/decrease based on tracking value of seekbar.
Here is the full example implemented using the SeekBar.
回答2:
Use this to change the brightness (system-wide)
ContentResolver cr = getContentResolver();
int brightness = Settings.System.getInt(cr,Settings.System.SCREEN_BRIGHTNESS);
Settings.System.putInt(cr, Settings.System.SCREEN_BRIGHTNESS, brightness);
WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.screenBrightness = brightness / 255.0f;
getWindow().setAttributes(lp);
You may use this example and call the above code in onProgressChanged()
. Default values of progress
range from 0 to 100.
回答3:
You can change the screen brightness using the WindowManager.LayoutParams.
Get the LayoutParams using getWindow().getAttributes()
then set the field screenBrightness
to a number between 0 to 1 (0 dark, 1 bright) and then call getWindow().setAttributes()
with your modified LayoutParams object.
来源:https://stackoverflow.com/questions/7845458/how-could-you-increase-the-screen-brightness-in-android-using-a-seek-bar