我的密钥代码连续
<Key android:codes="49" android:keyLabel="1" android:verticalGap="2%p" android:popupKeyboard="@xml/popupview" android:popupCharacters="wW" android:keyEdgeFlags="left"/>
它会显示一个带有'w'和'W'的弹出窗口,以及长按'1'时的十字按钮。但是没有动作监听器添加到这些角色。如果我点击'w'没有任何事情发生,但十字按钮工作。但是我怎样才能为这个角色添加动作监听器。提前谢谢:)
答案 0 :(得分:0)
您应首先查看here和here。这是full running sample。只需一个一个地复制它就可以了。
阅读本教程:Creating an Input Method 克隆这个仓库:LatinIME
和一些链接
How to make a Android custom keyboard?
Android custom keyboard xml file
您还可以在Android开发者网站上搜索Softkeyboard Android示例。
答案 1 :(得分:0)
My Solution: OnCreate:
mKeyboardView.setOnKeyboardActionListener(new ActionListener(
Activity.this,edittext, mKeyboardView));
public class BasicOnKeyboardActionListener implements KeyboardView.OnKeyboardActionListener {
EditText editText;
CustomKeyboardView displayKeyboardView;
private Activity mTargetActivity;
public ActionListener(Activity targetActivity, EditText editText,
CustomKeyboardView
displayKeyboardView) {
mTargetActivity = targetActivity;
this.editText = editText;
this.displayKeyboardView = displayKeyboardView;
}
@Override
public void onText(CharSequence text) {
int cursorPosition = editText.getSelectionEnd();
String previousText = editText.getText().toString();
String before, after;
if (cursorPosition < previousText.length()) {
before = previousText.substring(0, cursorPosition);
after = previousText.substring(cursorPosition);
} else {
before = previousText;
after = "";
}
editText.setText(before + text + after);
editText.setSelection(cursorPosition + 1);
}
@Override
public void onKey(int primaryCode, int[] keyCodes) {
switch (primaryCode) {
case xx:// xx is primaryCode that is given program for pressed key
onText("C");// C is char what you want to write
default:
break;
}
}
}