UiModeManager - NightMode (Froyo)

↘锁芯ラ 提交于 2019-12-09 06:44:50

问题


I have been trying to turn off the backlight of the buttons in my application using the UiModeManager's nightmode function. The default Desk Clock application (Nexus One) turns off the backlight when it is dimmed, and I want to do this as well.

I've tried using the following code:

UiModeManager mgr = (UiModeManager) getSystemService(UI_MODE_SERVICE); mgr.setNightMode(UiModeManager.MODE_NIGHT_YES);

The UiModeManager.setNightMode(int mode) documentation says this:

Sets the night mode. Changes to the night mode are only effective when the car or desk mode is enabled on a device.

Does that mean that the device has to be physically in a desk dock? I can set the device to car mode using the UiModeManager.enableCarMode(int flags) method. This works fine, but it doesn't turn off the lights, it only dims the screen's backlight.

Is there a way to set the device into desk mode without using a physical desk dock? As the FroYo source code is not yet released, I cannot look at the build-in Desk Clock application.


回答1:


Answering my own question as the Froyo source code has just been released:

I don't think you have to use the UIModeManager class. This is how the DeskClock app does:

Window win = getWindow();
WindowManager.LayoutParams winParams = win.getAttributes();

//Look at this!
winParams.buttonBrightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_OFF;

win.setAttributes(winParams);

..And it works for me as well.



来源:https://stackoverflow.com/questions/2892160/uimodemanager-nightmode-froyo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!