Android custom keyboard popup keyboard on long press(长按Android自定义键盘弹出键盘)
问题描述
我有自定义 Android 键盘:
I have custom Android keyboard:
public class CustomKeyboard extends Keyboard{...}
public class CustomKeyboardView extends KeyboardView{...}
public class CustomKeyboardIME extends InputMethodService implements KeyboardView.OnKeyboardActionListener{...}
在某些键上,我有 popupKeyboard
和 popupCharacters
:
On some keys, I have popupKeyboard
and popupCharacters
:
<Key android:codes="144" android:keyLabel="0" android:popupKeyboard="@xml/key_popup" android:popupCharacters=")" android:keyEdgeFlags="right"/>
xml/key_popup.xml:
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"按钮或)"字符.它看起来像这样:
But when I longPress on "0" key popup with ")" shows, but it stays there until I press "X" button or ")" character. It looks like this:
而且我希望它仅在我握着手指时打开.三星或 HTC 键盘之类的东西:
And I want it to be opened only while I am holding a finger on. Something like on Samsung or HTC keyboard:
有人可以帮帮我吗?
编辑至少可以改变这个弹出窗口的外观吗?我希望它具有与我制作的整个键盘相同的背景和键/
EDIT Is it at least possible to change the appearance of this popup? I want it to have same background and keys as whole keyboard I have made/
推荐答案
您可以使用 PopupWindow
类并使用自定义布局填充它.
You can use PopupWindow
class and populate it with custom layout.
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();
这篇关于长按Android自定义键盘弹出键盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:长按Android自定义键盘弹出键盘
基础教程推荐
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01