1.获取屏幕当前亮度
int screenBrightness = android.provider.Settings.System.getInt(getContentResolver(), android.provider.Settings.System.SCREEN_BRIGHTNESS, 255);
2.设置屏幕亮度
public void changeAppBrightness(Context context, int brightness) { Window window = ((Activity) context).getWindow(); WindowManager.LayoutParams lp = window.getAttributes(); if (brightness == -1) { lp.screenBrightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE; } else { lp.screenBrightness = (brightness <= 0 ? 1 : brightness) / 255f; } window.setAttributes(lp); }
网友评论