安卓2.2:调整屏幕亮度 [英] Android 2.2: Adjusting screen brightness

查看:205
本文介绍了安卓2.2:调整屏幕亮度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

    public void SetBright(float value) 
{
    Window mywindow = getWindow();

    WindowManager.LayoutParams lp = mywindow.getAttributes();

            lp.screenBrightness = value;

            mywindow.setAttributes(lp);
}

我要调整屏幕亮度。但是当我尝试使用这种方法没有任何反应。难道是因为我用的是KEEP_SCREEN_ON标志?

I want to adjust the screen brightness. But nothing happens when i try using this method. Could it be because i use the KEEP_SCREEN_ON flag?

推荐答案

确保自动亮度是不是之前设置屏幕亮度启用。您可以在设置>显示或使用code如果您使用的是Android 2.2或以上的SDK手动执行此操作。

Make sure that "Auto Brightness" is not enabled prior to setting the screen brightness. You can do this manually in Settings>Display or using code if you are using Android 2.2 or above SDK.

是这样的:

int brightnessMode = Settings.System.getInt(getContentResolver(), Settings.System.SCREEN_BRIGHTNESS_MODE);
if (brightnessMode == Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC) {
    Settings.System.putInt(getContentResolver(), Settings.System.SCREEN_BRIGHTNESS_MODE, Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL);
}

WindowManager.LayoutParams layoutParams = getWindow().getAttributes();
layoutParams.screenBrightness = 0.5F; // set 50% brightness
getWindow().setAttributes(layoutParams);

确保值为0.0F和1.0F之间。对-1.0F值使用存储在preferences默认亮度。每文档小于0的值,默认值,意味着要使用preferred屏幕亮度。0到1调整从暗到全亮的亮度。

Ensure the value is between 0.0F and 1.0F. A value of -1.0F uses the default brightness stored in the preferences. Per the documentation "A value of less than 0, the default, means to use the preferred screen brightness. 0 to 1 adjusts the brightness from dark to full bright."

这篇关于安卓2.2:调整屏幕亮度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆