Android IME:显示自定义弹出对话框(如 Swype 键盘),可以在 TextView 中输入文本
我想知道如何创建一个自定义弹出窗口,如下面的屏幕截图中的那样(借自 Swype 键盘),其中我可以有几个按钮,每个按钮都将一个字符串提交到当前“已连接”TextView
(通过 InputConnection)。
请注意:这是一个InputMethodService并且不是普通的Activity
。我已经尝试使用 Theme:Dialog
启动单独的 Activity
。然而,一旦打开它,我就会失去对 TextView 的焦点,并且我的键盘也会消失(随之我的 InputConnection
也消失了)。
I'm wondering how I can create a custom pop-up like the one in the screenshot below (borrowed from the Swype keyboard), where I can have a couple of buttons, which each commit a string to the currently "connected" TextView
(via a InputConnection).
Please note: this is an InputMethodService and not an ordinary Activity
. I already tried launching a separate Activity
with Theme:Dialog
. However, as soon as that one opens I lose my focus with the TextView
and my keyboard disappears (and with that my InputConnection
is gone).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以尝试使用
PopupWindow
。您必须做一些修改才能让它执行您想要的操作,而唯一好的文档就是源代码。You can try using a
PopupWindow
. You'll have to do a bit of hacking to get it to do what you want and the only good documentation for it is the source.我也曾为这个问题绞尽脑汁,最后终于解决了。上述解决方案是正确的,尽管正如您所指出的,它们不能从 InputMethodService 中使用,因为它不是 Activity。诀窍是在 KeyboardView 的子类中创建 PopupWindow 。通过使用负 Y 位置,PopupWindow 可以像 Swype 一样出现在键盘上方。
祝你好运,
巴里
I was banging my head against this problem too and I finally figured it out. The above solutions are correct although as you pointed out they cannot be used from an InputMethodService because it is not an Activity. The trick is to create the PopupWindow in a subclass of KeyboardView. By using a negative Y position, the PopupWindow can appear above the keyboard like Swype.
Good luck,
Barry
正确答案:
这将在 IME 上方显示您的弹出窗口,如屏幕截图所示。
Correct answer:
This will show your popup above the IME as in your screenshot.
愿那些遵循指导的人平安,
解决方案:
===== 更新 30.09.2015
mInputView 它是键盘类的通用名称..请参阅
更多信息: http://developer.android.com/guide/topics/text/creating-input-method.html
祝你好运。
Peace be upon those who follow the guidance,
solution :
===== UPDATE 30.09.2015
mInputView its the general name of your keyboard class ..see
More info : http://developer.android.com/guide/topics/text/creating-input-method.html
good luck.