开发者

Turn off Button Backlight (like Nexus 1 soft buttons)

I know this is possible as the built in clock app and other apps are able to do it.

How do you turn 开发者_开发技巧off the button backlights from code? These would be those like the softkeys on the bottom of the Nexus One screen.

Update:

Found this, but it only works on Froyo:

WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.buttonBrightness = 0;

Any other ideas?


alex had an answer to this- although it is a hack. Since buttonBrightness was a private field before froyo, it uses reflection to access it.

Turn off backlight of the buttons

and this is how I use it in my project:

final Window win = getWindow();
final WindowManager.LayoutParams winParams = win.getAttributes();
winParams.flags |= WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;

//set screen brightness to the lowest possible
winParams.screenBrightness = 0.01f;

if (Build.VERSION.SDK_INT < 8) {
    // hack for pre-froyo to set buttonBrightness off
    try {
        Field buttonBrightness = winParams.getClass().getField(
                "buttonBrightness");
        buttonBrightness.set(winParams, 0);
    } catch (Exception e) {
        e.printStackTrace();
    }
} else {
    winParams.buttonBrightness = 0;
}

win.setAttributes(winParams);


Refer to this section of the Android documentation: http://developer.android.com/reference/android/os/PowerManager.html

PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "My Tag");
wl.acquire();
   //screen will stay on during this section...
wl.release();

By calling SCREEN_DIM_WAKE_LOCK you will set the screen to dim and the keyboard to off. Alternatively, you can call SCREEN_BRIGHT_WAKE_LOCK which sets the screen to bright and the keyboard to off or PARTIAL_WAKE_LOCK which turns both the screen and the keyboard off.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜