KeyEventCompat not supported at build

Seb picture Seb · Apr 30, 2018 · Viewed 10.6k times · Source

My project is currently using but seems I have moved to api level 26 - revision 26.0.2, I am struggling to find the symbol KeyEventCompat

import android.support.v4.view.KeyEventCompat;

I try to figure out using v7 but it's not working. Any idea on how to make it works.

Example of use:

case KeyEvent.KEYCODE_TAB:
    if (KeyEventCompat.hasNoModifiers(event)) {
        handled = arrowScroll(FOCUS_FORWARD);
    } else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_SHIFT_ON)) {
        handled = arrowScroll(FOCUS_BACKWARD);
    }
    break;

Any idea on how to make it works.

Thanks

Answer

Madhur picture Madhur · Jun 20, 2018

change this

if (KeyEventCompat.hasNoModifiers(event)) {
    handled = arrowScroll(FOCUS_FORWARD);
} else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_SHIFT_ON)) {
    handled = arrowScroll(FOCUS_BACKWARD);
}

to

if (event.hasNoModifiers()) {
    handled = arrowScroll(FOCUS_FORWARD);
} else if (event.hasModifiers(KeyEvent.META_SHIFT_ON)) {
    handled = arrowScroll(FOCUS_BACKWARD);
}

KeyEventCompat class was deprecated in API level 26.0.0