查看特定的输入法?

发布于 2024-11-04 19:40:35 字数 271 浏览 0 评论 0原文

我有一个自定义视图,我希望用户能够从应用程序定义的字符集中输入字符。据我了解,要做到这一点,我需要编写一个输入法服务。用户不仅需要安装它,还需要在“设置”>“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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

猫卆 2024-11-11 19:40:35

我不认为 IME 是为此类任务而设计的。他们的概念是允许用户以标准化方式输入,以便可以在不同供应商的多个应用程序中使用。

我的策略与您的想法类似:

  • 阻止软键盘出现,
  • 拦截菜单按钮按键以显示您自己的按键,
  • 添加自定义布局(可能是 GridView 或 )具有底部重力的 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:

  • prevent the soft keyboard from appearing,
  • intercept the menu button key press to show your own instead,
  • add a custom layout (probably a GridView or a TableView inside a RelativeLayout with bottom gravity)
  • use an OnItemClickListener
  • send the required KeyEvents to the root View. If the characters are invented, the KeyCodes 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 the GridView.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文