带自定义键的Android自定义键盘(按键中的单词)

时间:2018-01-16 20:22:50

标签: android android-studio

我想用自己的键创建键盘。我确实学会了如何制作qwerty键盘,现在我改变了适合键盘的布局。

但我想在一键按下添加单词,是否可能?

<Key android: codes="104 101 108 108 111" android: keyLabel="h" />
像这样,除了单键之外,按键'h'键入“hello”,我还想在最后一个位置添加DONE(-4)按钮来发送文本。 用逗号表示可选键[h / e / l / l / o]。由于空间原因,上面的代码是错误的。 任何帮助。 参考:https://github.com/tutsplus/Android-CustomKeyboard 刚刚编辑了qwerty.xml来设置我的设计,现在坚持这个。

1 个答案:

答案 0 :(得分:0)

我假设您已经通过扩展InputMethodService来准备键盘,这是标准的方法。

对于您引用的示例,文件SimpleIME.java具有函数

  

public void onKey(int primaryCode,int [] keyCodes){

您需要在

中添加密钥代码案例
  

开关(primaryCode){

并像这样处理:

CharSequence text = "your text here";
InputConnection ic = getCurrentInputConnection();
if (ic != null) {
    ic.commitText(text, 1);
}

希望有所帮助〜

相关问题