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_preview_layout”
/>
- 其中
android:keyPreviewLayout
指的是每当我们点击键盘上的某个键时,短暂弹出的布局。
| 属性名 | 描述 |
| — | — |
| android:keyBackground | Image for the key. |
| android:keyPreviewLayout | Layout resource for key press feedback. |
| android:keyPreviewOffset | Vertical offset of the key press feedback from the key. |
| android:keyTextColor | Color to use for the label in a key. |
| android:keyTextSize | Size of the text for character keys. |
| android:labelTextSize | Size of the text for custom keys with some text and no icon. |
| android:popupLayout | Layout resource for popup keyboards. |
| android:verticalCorrection | Amount to offset the touch Y coordinate by, for bias correction. |
- 我们需要建一个
xml文件
,来布局我们的视图,
一般是在res
文件夹中建一个名为xml的文件夹,在里面新建立一个xml布局文件。
- 每一个按键的属性主要包括