关闭按钮背光(如Nexus 1软按钮)按钮、Nexus

2023-09-07 13:12:08 作者:弹猫的吉他

我知道这是可能的,内置的时钟程序和其他应用程序都能够做到这一点。

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

你如何关闭从code按键背光?这些将是那些像Nexus One的屏幕下方的功能键。

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.

更新:

发现这一点,但它仅适用于Froyo的:

Found this, but it only works on Froyo:

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

任何其他的想法?

Any other ideas?

推荐答案

亚历克斯的答案,这 - 虽然这是一个黑客。由于buttonBrightness是Froyo的前一个私有字段,它使用反射来访问它。

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.

关闭按钮的背光

这就是我如何使用它在我的项目:

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);