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 a开发者_开发问答pplication (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.
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.
精彩评论