【问题标题】:Android custom keyboard popup keyboard on long press长按Android自定义键盘弹出键盘
【发布时间】:2015-06-06 01:31:40
【问题描述】:

我有自定义 Android 键盘:

    public class CustomKeyboard extends Keyboard{...}  

    public class CustomKeyboardView extends KeyboardView{...}

    public class CustomKeyboardIME extends InputMethodService implements KeyboardView.OnKeyboardActionListener{...}  

在某些键上,我有popupKeyboardpopupCharacters

<Key android:codes="144" android:keyLabel="0" android:popupKeyboard="@xml/key_popup" android:popupCharacters=")" android:keyEdgeFlags="right"/>

xml/key_popup.xml:

<Keyboard xmlns:android="http://schemas.android.com/apk/res/android"
      android:keyWidth="10%p"
      android:horizontalGap="0px"
      android:verticalGap="0px"
      android:keyHeight="@dimen/key_height" >
</Keyboard>

但是当我长按“0”键弹出“)”显示,但它一直停留在那里,直到我按下“X”按钮或“)”字符。它看起来像这样:

而且我希望它仅在我握着手指时打开。三星或 HTC 键盘之类的东西:

有人可以帮帮我吗?

编辑至少可以改变这个弹出窗口的外观吗?我希望它具有与我制作的整个键盘相同的背景和键/

【问题讨论】:

标签: android keyboard android-softkeyboard keyboard-events android-input-method


【解决方案1】:

您可以使用PopupWindow 类并使用自定义布局填充它。

View custom = LayoutInflater.from(context)
    .inflate(R.layout.your_layout, new FrameLayout(context));
PopupWindow popup = new PopupWindow(context);
popup.setContentView(custom);

长按

//Get x,y based on the touch position
//Get width, height based on your layout
if(popup.isShowing()){
    popup.update(x, y, width, height);
} else {
    popup.setWidth(width);
    popup.setHeight(height);
    popup.showAtLocation(yourKeyboardView, Gravity.NO_GRAVITY, x, y);
}

点击弹窗即可关闭

popup.dismiss();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-11-12
    • 2017-10-21
    • 1970-01-01
    • 2015-11-20
    • 1970-01-01
    • 2018-06-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多