比如在viewpager中点击音量键调节上一页下一页,return true就可以取消音量界面的显示
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (voiceRead.equals("open")) {
if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
vp.setCurrentItem(vp.getCurrentItem()+1);
return true;
} else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
vp.setCurrentItem(vp.getCurrentItem()-1);
return true;
}
}
return super.onKeyDown(keyCode, event);
}
转载于:https://blog.51cto.com/7540017/1621661