使用RecyclerView发现只有左右按键声,但是没有上下
public class SoundRecyclerView extends RecyclerView {
public SoundRecyclerView(@NonNull Context context) {
super(context);
}
public SoundRecyclerView(@NonNull Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
}
public SoundRecyclerView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
public boolean dispatchKeyEventPreIme(KeyEvent event) {
if (event.getAction() == KeyEvent.ACTION_DOWN){
switch (event.getKeyCode()){
case KeyEvent.KEYCODE_DPAD_UP:
playSoundEffect(SoundEffectConstants.NAVIGATION_UP);
break;
case KeyEvent.KEYCODE_DPAD_DOWN:
playSoundEffect(SoundEffectConstants.NAVIGATION_DOWN);
break;
// case KeyEvent.KEYCODE_DPAD_RIGHT:
// playSoundEffect(SoundEffectConstants.NAVIGATION_RIGHT);
// break;
// case KeyEvent.KEYCODE_DPAD_LEFT:
// playSoundEffect(SoundEffectConstants.NAVIGATION_LEFT);
// break;
}
}
return super.dispatchKeyEventPreIme(event);
}
}