我知道这是可行的,因为内置时钟应用程序和其他应用程序能够做到这一点。
如何从代码中关闭按钮背光?这些就像是Nexus One屏幕底部的软键。
更新
找到了这个,但它只适用于Froyo:
WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.buttonBrightness = 0;
还有其他想法吗?
答案 0 :(得分:1)
Turn off backlight of the buttons
这就是我在项目中使用它的方式:
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);
答案 1 :(得分:0)
请参阅Android文档的此部分: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();
通过调用SCREEN_DIM_WAKE_LOCK,您将屏幕设置为暗淡,键盘设置为关闭。或者,您可以调用SCREEN_BRIGHT_WAKE_LOCK,将屏幕设置为明亮,键盘设置为关闭或PARTIAL_WAKE_LOCK,这将关闭屏幕和键盘。