我有一个自定义视图,我希望用户能够从应用程序定义的字符集输入字符。 要做到这一点,据我所知,我需要编写一个输入法服务。 用户不仅需要安装它,还需要在设置>语言和键盘中启用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?
最满意答案
我不认为IME是为这种任务而设想的。 他们的概念是以标准化方式允许用户输入,因此可以在不同供应商的多个应用程序中使用。
我的策略与您的想法类似:
防止软键盘出现, 拦截菜单按钮按键显示你自己的, 添加自定义布局(可能是具有底部重力的RelativeLayout内的GridView或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.
特定于视图的IME?(View-specific 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?
最满意答案
我不认为IME是为这种任务而设想的。 他们的概念是以标准化方式允许用户输入,因此可以在不同供应商的多个应用程序中使用。
我的策略与您的想法类似:
防止软键盘出现, 拦截菜单按钮按键显示你自己的, 添加自定义布局(可能是具有底部重力的RelativeLayout内的GridView或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.
发布评论