我正在开发一种 Android 输入法,其中一项任务是为硬键盘按键实现自定义弹出键盘。通常输入法让编辑器处理这个问题,但问题是我需要添加比 android 支持更多的符号。 所以我实现了弹出键盘,甚至在长按硬键(字符键)时它也能很好地显示。
我遵循的步骤是:
- 创建弹出窗口。
- 膨胀包含键盘 View 和关闭按钮的线性布局并将其保存到 View 对象
- 将键盘 View 和关闭按钮绑定(bind)到相关对象
- 为弹出字符创建一个键盘,并将其设置为键盘 View 的键盘。键盘的列数限制为 5。
- 将线性布局设置为弹出窗口的内容 View
- 显示弹出窗口
问题:如果弹出键盘中有多行,我只能选择该列最后一行中的键。即使我单击该列第一行中的键,最后一行中的键也会被选中。 如果有人能解释为什么会发生这种情况以及如何解决它,我将不胜感激。
代码:
PopupWindow mPopupKeyboard = new PopupWindow(this.getBaseContext());
mPopupKeyboard.setBackgroundDrawable(null);
if(mPopupKeyboard != null)
{
this.dismissPopupKeyboard();
View mMiniKeyboardContainer = null;
KeyboardView mMiniKeyboard = null;
View closeButton = null;
mMiniKeyboardContainer = getLayoutInflater().inflate(R.layout.keyboard_popup_keyboard, null);
mMiniKeyboard = (KeyboardView) mMiniKeyboardContainer.findViewById(R.id.popup_keyboardView);
closeButton = mMiniKeyboardContainer.findViewById(R.id.closeButton);
if (closeButton != null)
{
closeButton.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View arg0)
{
mPopupKeyboard.dismiss();
});
}
mMiniKeyboard.setOnKeyboardActionListener(this);
String resourcestring = "abcdefghi";
mMiniKeyboard.setKeyboard(new Keyboard(this.getBaseContext(), R.xml.kbd_popup_template, alternates, 3, 0));
mMiniKeyboard.setPopupParent(mCandidateView);
mPopupKeyboard.setContentView(mMiniKeyboardContainer);
mPopupKeyboard.setWidth(LayoutParams.WRAP_CONTENT);
mPopupKeyboard.setHeight(LayoutParams.WRAP_CONTENT);
mPopupKeyboard.showAtLocation(mCandidateView, Gravity.TOP, 0, 0);
}
最佳答案
我在弹出键盘时遇到了类似的问题。我发现只有Android 2.3有这个问题。我唯一的解决方法是避免弹出键盘超过一行。
关于android - 当指定列限制时,android 中的弹出键盘问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9350654/