我想在我的Android应用程序中使用搜索栏来增加屏幕的亮度,但我不知道如何做到这一点。如何添加此功能?
答案 0 :(得分:4)
使用此功能,您可以设置屏幕亮度:
WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.screenBrightness = 100 / 100.0f;
getWindow().setAttributes(lp);
现在,由于你想实现像控制一样的进度条,我建议你实现SeekBar,所以使用它你可以根据搜索栏的跟踪值轻松增加/减少。
Here是使用SeekBar实现的完整示例。
答案 1 :(得分:1)
使用此项更改亮度(系统范围)
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);
您可以使用this example并在onProgressChanged()
中调用上述代码。默认值progress
的范围为0到100.
答案 2 :(得分:0)
您可以使用WindowManager.LayoutParams更改屏幕亮度。
使用getWindow().getAttributes()
获取LayoutParams,然后将字段screenBrightness
设置为0到1(0暗,1亮)之间的数字,然后使用修改后的LayoutParams对象调用getWindow().setAttributes()
。