关闭按钮背光(如Nexus 1软按钮) [英] Turn off Button Backlight (like Nexus 1 soft buttons)

查看:98
本文介绍了关闭按钮背光(如Nexus 1软按钮)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

这篇关于关闭按钮背光(如Nexus 1软按钮)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆