0
我想用音量鍵更改屏幕的亮度。我使用此代碼,但它不起作用:在Android中使用音量鍵更改亮度屏幕
@Override
public boolean onKeyDown(int keyCode,KeyEvent keyEvent){
WindowManager.LayoutParams layout = getWindow().getAttributes();
if(keyEvent.getAction() == KeyEvent.ACTION_DOWN){
switch (keyCode){
case KeyEvent.KEYCODE_VOLUME_DOWN:
layout.screenBrightness -= 0.1;
getWindow().setAttributes(layout);
break;
case KeyEvent.KEYCODE_VOLUME_UP:
layout.screenBrightness += 0.1;
getWindow().setAttributes(layout);
break;
}
}
return super.onKeyDown(keyCode , keyEvent);
}
當我按音量鍵向下/向上鈴聲音量改變?