<Key android:codes=“-5”
android:keyIcon=“@drawable/sym_keyboard_delete”/>
再监听就是:
if (primaryCode == Keyboard.KEYCODE_DELETE){}
这就表示,监听 delete
事件了!
定义 <Key/>
标签时常用到的 codes / KEYCODE
有:
public static final int KEYCODE_SHIFT = -1;
public static final int KEYCODE_MODE_CHANGE = -2;
public static final int KEYCODE_CANCEL = -3;
public static final int KEYCODE_DONE = -4;
public static final int KEYCODE_DELETE = -5;
public static final int KEYCODE_ALT = -6;
2. KeyboardView
处理绘制,检测按键,触摸动作:
- A view that renders a virtual
Keyboard
. It handles rendering of keys and detecting key presses and touch movements.
我们会在Activity的xml文件中这样定义:
<android.inputmethodservice.KeyboardView
android:id=“@+id/keyboard_view”
android:layout_width=“match_parent”
android:layout_height=“wrap_content”
android:layout_alignParentBottom=“true”
android:background=“@color/gray”
android:focusable=“true”
android:focusableInTouchMode=“true”
android:keyBackground=“@drawable/bg_keyboard_selector”
android:keyTextColor=“@color/keyTextColor”
android:visibility=“gone”
android:keyPreviewLayout=“@layout/key