将信息从 EditText 发送到 IME
我正在编写一个语言学习应用程序,目前只有德语<->俄语。
有几个 EditTexts
,用户应该在其中以一种或另一种语言输入文本。由于这些语言使用不同的字母表,因此应用程序通过实现 InputMethodService
并提供拉丁语和西里尔语键盘布局来使用自己的软键盘。每个 EditText
字段都知道需要哪种语言。
我想要的是,例如,每当需要俄语的 EditText
字段处于焦点时,就应该显示西里尔字母键盘布局。选择后,EditText
应将一些常量传递给 IME,后者可使用该常量来决定是否以拉丁语或西里尔语模式显示。
理想情况下,只需为 EditText
指定一些自定义 InputType
,但这似乎不可能,不是吗?这里正确的做法是什么?
I'm writing a language learning app, currently only German<->Russian.
There are several EditTexts
where the user is supposed to enter text in one or the other language. As these languages use different alphabets, the app uses its own soft keyboard by implementing InputMethodService
and providing both Latin and Cyrillic keyboard layout. It is known for each EditText
field which language is expected.
What I would like is that, e.g., whenever an EditText
field expecting Russian is in focus, the Cyrillic keyboard layout should be displayed. When selected, the EditText
should pass some constant on to the IME, which the latter can use to decide whether to display in Latin or Cyrillic mode.
Ideally, one would simply specify some custom InputType
for the EditText
but that doesn't seem to be possible, does it? What is the correct approach here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你的想法听起来不错。 IME 的代码检查开关块中的
InputType
,如果InputType
不匹配,则显示默认键盘布局。您还可以在
Activity
的onCreate()
方法中提供逻辑,以检查哪个输入法处于活动状态,并根据该信息选择您的inputType
EditText
应该有。Your idea doesn't sound bad. IME's code check for the
InputType
in a switch block and the default keyboard layout is shown if theInputType
didn't match.You can also provide a logic in
onCreate()
method of yourActivity
to check which input method is active and with that info choose whichinputType
yourEditText
should have.