在项目中,产品对于输入方式会有特殊的要求,需要对输入方式增加特定的限制,这就需要采用自定义键盘。本文主要讲述数字键盘和字母键盘的自定义实现。
自定义键盘的实现步骤如下:
自定义CustomKeyboard,继承自系统Keyboard,实现KeyboardView.OnKeyboardActionListener相关接口,以处理用户的点击回调;
自定义CustomKeyboardView,继承自KeyboardView,实现自定义键盘绘制;
创建KeyboardManager,用于处理自定义键盘的显示以及和输入UI的交互
自定义CustomKeyboard
Android系统Keyboard的构造方法如下:
/**
* Creates a keyboard from the given xml key layout file.
* @param context the application or service context
* @param xmlLayoutResId the resource file that contains the keyboard layout and keys.
*/
public Keyboard(Context context,int xmlLayoutResId) {
this(context,xmlLayoutResId,0);
}
/**
* Creates a keyboard from the given xml key layout file. Weeds out rows
* that have a keyboard mode defined but don't match the specified mode.
* @param context the application or service context
* @param xmlLayoutResId the resource file that contains the keyboard layout and keys.
* @