如何在我的自定义键盘中将动作侦听器设置为弹出键盘...
how to set action listener to popup keyboard in my custom keyboard...
我的关键代码连续
<Key android:codes="49" android:keyLabel="1" android:verticalGap="2%p" android:popupKeyboard="@xml/popupview" android:popupCharacters="wW" android:keyEdgeFlags="left"/>
当长按“1”时,它会显示一个带有 'w' 和 'W' 的弹出窗口 window 和一个十字按钮。但是这些角色没有添加动作侦听器。如果我单击 'w' 没有任何反应,但十字按钮有效。但是我怎样才能为这个角色添加动作侦听器。提前致谢:)
你应该先看看here and here . And this is full running sample。只需一张一张复制即可。
阅读本教程:Creating an Input Method
克隆这个 repo:LatinIME
还有一些链接
How to make a Android custom keyboard?
Android custom keyboard xml file
您还可以在 Android 开发者网站上搜索软键盘 Android 示例。
我的解决方案:
创建时:
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;
}
}
}
我的关键代码连续
<Key android:codes="49" android:keyLabel="1" android:verticalGap="2%p" android:popupKeyboard="@xml/popupview" android:popupCharacters="wW" android:keyEdgeFlags="left"/>
当长按“1”时,它会显示一个带有 'w' 和 'W' 的弹出窗口 window 和一个十字按钮。但是这些角色没有添加动作侦听器。如果我单击 'w' 没有任何反应,但十字按钮有效。但是我怎样才能为这个角色添加动作侦听器。提前致谢:)
你应该先看看here and here . And this is full running sample。只需一张一张复制即可。
阅读本教程:Creating an Input Method 克隆这个 repo:LatinIME
还有一些链接
How to make a Android custom keyboard?
Android custom keyboard xml file
您还可以在 Android 开发者网站上搜索软键盘 Android 示例。
我的解决方案: 创建时:
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;
}
}
}