[英]Adjusting screen brightness using WindowManager stops working after inactivity
我正在使用此代碼通過調暗來更改 Activity 的亮度。
WindowManager.LayoutParams layoutParameters = getWindow().getAttributes();
layoutParameters.screenBrightness = 0.0075f;
getWindow().setAttributes(layoutParameters);
我也在調整 android.provider.Settings.System 亮度。
我的問題是,大約 8 秒不活動后,屏幕亮度恢復正常(即再次變亮)。 有誰知道為什么會發生這種情況以及我如何更改該設置?
謝謝!
我不知道它是否會覆蓋您的 layoutParameters,但也許可以嘗試使用完整的wakeLock來防止屏幕變暗。
您應該將 Settings.System.SCREEN_BRIGHTNESS_MODE 的值從 Automatic 更改為 manual,然后更改 int 值 Settings.System.SCREEN_BRIGHTNESS。 只添加這些代碼行:
Settings.System.putInt(getActivity().getContentResolver(), Settings.System.SCREEN_BRIGHTNESS_MODE, Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL);
Settings.System.putInt(getActivity().getContentResolver(), Settings.System.SCREEN_BRIGHTNESS, brightness);//for persistent change
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.