查看特定的输入法?
我有一个自定义视图,我希望用户能够从应用程序定义的字符集中输入字符。据我了解,要做到这一点,我需要编写一个输入法服务。用户不仅需要安装它,还需要在“设置”>“IME”中启用IME。语言与键盘,然后选择要在视图中使用的自定义 IME。
这看起来真的很疯狂。我希望此 IME 仅用于一个应用程序中的一个视图。我不希望它在系统范围内可用或强制用户进行全局设置更改。
我能看到的唯一替代方案是定义我自己的应用内自定义视图,并在视图获得焦点时模拟 IME(可能是全屏 IME)。难道就没有更好的了吗?
I have a custom view for which I want the user to be able to enter characters from an app-defined set of characters. To do this, as I understand it, I need to write an input method service. The user not only needs to install it, but then needs to enable the IME in the Settings > Language & keyboard, and then select the custom IME for use in the view.
This seems really crazy. I want this IME to be used for just one view in one application. I don't want it to be available system-wide or force the user to make global setting changes.
The only alternative I can see is defining my own in-app custom view and simulate an IME (probably a full-screen one) when the view gains focus. Isn't there anything better?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不认为 IME 是为此类任务而设计的。他们的概念是允许用户以标准化方式输入,以便可以在不同供应商的多个应用程序中使用。
我的策略与您的想法类似:
RelativeLayout
内的 TableView)OnItemClickListener
KeyEvent
发送到根View.如果字符被发明,
KeyCodes
甚至不需要与 ASCII 字符相关。你只要截取代码,随意使用即可。抱歉,我无法按照您的要求为您提供一个选项,但这种替代方案似乎并不比创建一个全新的 IME 需要更多工作。
编辑:阅读相关问题后,使用
android.inputmethodservice.KeyboardView
而不是使用GridView
重新发明轮子是有意义的。I do not think the IMEs are conceived for that kind of task. Their concept is to allow user input in a standardized way so it can be used across multiple applications from different vendors.
My strategy would be similar to what you are thinking:
GridView
or aTableView
inside aRelativeLayout
with bottom gravity)OnItemClickListener
KeyEvent
s to the rootView
. If the characters are invented, theKeyCodes
do not even need to relate to the ASCII character. You just intercept the code and use at will.Sorry I can't give you an option as you asked, but this alternative does not seem to be much more work than creating a whole new IME.
Edit: upon reading the related question, it makes sense to use
android.inputmethodservice.KeyboardView
instead of reinventing the wheel with theGridView
.