android - 当指定列限制时,android 中的弹出键盘问题

标签 android keyboard popupwindow

我正在开发一种 Android 输入法,其中一项任务是为硬键盘按键实现自定义弹出键盘。通常输入法让编辑器处理这个问题,但问题是我需要添加比 android 支持更多的符号。 所以我实现了弹出键盘,甚至在长按硬键(字符键)时它也能很好地显示。

我遵循的步骤是:

  1. 创建弹出窗口。
  2. 膨胀包含键盘 View 和关闭按钮的线性布局并将其保存到 View 对象
  3. 将键盘 View 和关闭按钮绑定(bind)到相关对象
  4. 为弹出字符创建一个键盘,并将其设置为键盘 View 的键盘。键盘的列数限制为 5。
  5. 将线性布局设置为弹出窗口的内容 View
  6. 显示弹出窗口

问题:如果弹出键盘中有多行,我只能选择该列最后一行中的键。即使我单击该列第一行中的键,最后一行中的键也会被选中。 如果有人能解释为什么会发生这种情况以及如何解决它,我将不胜感激。

代码:

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/

相关文章:

Android License Server 检查总是超时

android - 后台收到通知时在谷歌地图中添加标记

android - 用于 java/android 的 youtube api,如何开始?

java - 无法更改软键盘上的按键图标

c - 键盘输入,不同的按键有不同的响应

javascript - Sweet Alert JS库-修改动画速度

android - 扩展 SupportMapFragment 在加载 fragment 时显示全黑屏

jquery - 选择、聚焦或始终显示 iPad 键盘 (jQuery)

php - 从 mysql 数据库检索图像到数组 php

javascript - 如何显示弹出窗口