我正在开发Android自定义键盘。我在我的代码中导入了android.view.inputmethod.InputMethodSubtype
,同时这样做我收到了一个错误消息,像这样导入的无法解析。是否有任何我需要安装的eclipse插件,根据我的知识Android 1.6以上的版本将支持IMF。Android自定义键盘实现
1
A
回答
0
这个问题很古老,但我正在回答它,因为它可能会帮助另一个看到此问题的用户。
OP询问是否有Eclipse的任何插件来安装来解决问题,但现在我们有Android Studio。
对于那些想要实施Android Custom Keyboard: 首先,请下载Android自定义键盘的Google示例项目以开始。
有三个重要的功能来决定你想要哪一个:1)主题(自定义布局),2)子类型和3)表情符号。
对于主题/布局:创建布局文件。请参见下面的示例代码:
<com.domain.keyboard.android.LatinKeyboardView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/keyboard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="@drawable/kb_bg_9"
android:keyBackground="@drawable/key_bg_fill_white"
android:keyPreviewLayout="@layout/key_preview_layout"
android:keyPreviewOffset="@dimen/keyPreviewOffset"
android:keyTextColor="@color/white"
android:popupLayout="@layout/keyboard_popup_layout" />
而且在SoftKeyboard.java
使用下面的代码:
@Override
public View onCreateInputView() {
// Set custom theme to input view.
int themeLayout = sharedPreferences.getInt(THEME_KEY, R.layout.input_1);
mInputView = (LatinKeyboardView) getLayoutInflater().inflate(
themeLayout, null);
mInputView.setOnKeyboardActionListener(this);
// Close popup keyboard when screen is touched, if it's showing
mInputView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
mInputView.closing();
}
return false;
}
});
// Apply the selected keyboard to the input view.
setLatinKeyboard(getSelectedSubtype());
return mInputView;
}
亚型:创建的qwerty.xml
副本,并编辑它来代替钥匙。在SoftKeyboard.java
中创建LatinKeyboard
的另一个实例,并使用if
或switch
逻辑。
private LatinKeyboard getSelectedSubtype() {
final InputMethodSubtype subtype = mInputMethodManager.getCurrentInputMethodSubtype();
String s = subtype.getLocale();
switch (s) {
case "ps_AF":
mActiveKeyboard = mPashtoKeyboard;
mCurKeyboard = mPashtoKeyboard;
break;
case "fa_AF":
mCurKeyboard = mFarsiKeyboard;
break;
default:
mCurKeyboard = mQwertyKeyboard;
}
return mCurKeyboard;
}
和编辑methods.xml
添加亚型:
<input-method xmlns:android="http://schemas.android.com/apk/res/android"
android:settingsActivity="com.sunzala.afghankeyboard.android.ImePreferences"
android:supportsSwitchingToNextInputMethod="true">
<subtype
android:imeSubtypeLocale="en_US"
android:imeSubtypeMode="keyboard"
android:label="@string/label_subtype_generic" />
<subtype
android:imeSubtypeLocale="ps_AF"
android:imeSubtypeMode="keyboard"
android:label="@string/label_subtype_generic" />
<subtype
android:imeSubtypeLocale="fa_AF"
android:imeSubtypeMode="keyboard"
android:label="@string/label_subtype_generic" />
</input-method>
对于表情:查找库,并将其与键盘相结合。表情符号将按键显示。
if (primaryCode == -10000) {
showEmoticons();
}
其中-10000
是键码。
相关问题
- 1. Android自定义键盘
- 2. android键盘的自定义键
- 3. 实现Android键盘与popupwindow
- 4. 自定义键盘不显示自定义键盘iOS 8
- 5. 反应本机自定义Android键盘
- 6. android自定义软键盘拦截ime_action
- 7. 自定义Android键盘输入筛选
- 8. 自定义键盘像Gboard的Android
- 9. 创建自定义Android键盘布局
- 10. Android自定义键盘密码记录
- 11. 为android创建自定义键盘
- 12. Android:带自定义键盘的EditText
- 13. Android自定义键盘背景
- 14. 键盘自定义对话Android
- 15. Android键盘自动出现
- 16. 自定义Android键盘:如何创建辅助键盘
- 17. 在Android自定义键盘中设置键盘模式
- 18. 如何在自定义键盘中实现“向前删除”?
- 19. 为EditText实现自定义数字小键盘
- 20. 如何使用UIWebview实现自定义键盘?
- 21. 自定义对话框上的自定义键盘(Android)
- 22. 自定义iphone键盘
- 23. iPad自定义键盘GUI
- 24. 自定义iPhone键盘
- 25. iOS的自定义键盘
- 26. xcode 4 - 自定义键盘
- 27. 自定义安卓键盘
- 28. 自定义键盘预想
- 29. iPhone自定义键盘
- 30. 自定义数字键盘