我一直在尝试使用 UiModeManager 的夜间模式功能关闭我的应用程序中按钮的背光。默认的 Desk Clock 应用程序 (Nexus One) 在变暗时会关闭背光,我也想这样做。
我试过使用下面的代码:
UiModeManager mgr = (UiModeManager) getSystemService(UI_MODE_SERVICE); mgr.setNightMode(UiModeManager.MODE_NIGHT_YES);
UiModeManager.setNightMode(int mode) 文档是这样说的:
Sets the night mode. Changes to the night mode are only effective when the car or desk mode is enabled on a device.
这是否意味着设备必须物理地放在桌面扩展坞中? 我可以使用 UiModeManager.enableCarMode(int flags) 方法将设备设置为汽车模式。这工作正常,但它不会关闭灯,它只会调暗屏幕的背光。
有没有办法在不使用物理桌面扩展坞的情况下将设备设置为桌面模式?由于 FroYo 源代码尚未发布,我无法查看内置的 Desk Clock 应用程序。
最佳答案
回答我自己的问题,因为 Froyo 源代码刚刚发布:
我认为您不必使用 UIModeManager 类。 DeskClock 应用程序的工作方式如下:
Window win = getWindow();
WindowManager.LayoutParams winParams = win.getAttributes();
//Look at this!
winParams.buttonBrightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_OFF;
win.setAttributes(winParams);
..它也适用于我。
关于android - UiModeManager - 夜间模式 (Froyo),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2892160/