我想用音量键改变屏幕的亮度。我使用了这段代码,但它不起作用:
@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);
}
当我按音量键向下/向上时,铃声音量会改变吗?