问题描述
在我的应用程序中,用户选择一种语言,并且我想在键盘打开时显示所选的语言(如果键盘选项中存在该语言).键盘提供了该选项,因此应该可以.
In my application the user selects a language and I want to show the selected language when the keyboard opens (if it is present in the keyboard options). The keyboard provides that option, so it should be possible.
推荐答案
关于如何执行此操作有很大的工作-这是创建自己的键盘,并且要执行此操作,您必须知道自己的键盘重新瞄准. (与普通键盘完全相同)
There is a big work around about how to do this - which is create your own keyboard, and to do this you'll have to know the keyboards you're aiming for. (which will be exact duplicate of the regular keyboard)
General guide on the subject here & code samples.
创建自定义键盘视图,该键盘视图扩展了keyboardView
在其中创建静态键值变量,如
Create a custom keyboard View which extends keyboardView
In it create static key value variable like
static final int KEYCODE_LANGUAGE_SWITCH_ENG = -102;
static final int KEYCODE_LANGUAGE_SWITCH_URDU = -103;
之后,在实现了inputMethodService的IME类中,在onInitializeInterface覆盖函数内创建键盘.喜欢
after that in your IME class where you have implemented the inputMethodService, create the keyboards inside the onInitializeInterface override function. like
mSymbolsKeyboard = new Keyboard(this, R.xml.qwerty2);
mEngQwertyKeyboard = new Keyboard(this, R.xml.eng_qwerty);
此后,将这些最终的静态键添加到onKey覆盖功能中作为切换用例,并在这种情况下相应地设置键盘:
after this add these final static keys in the onKey override function as switch cases, and in the cases set the keyboards accordingly:
setKeyboard(mEngQwertyKeyboard);
这篇关于以编程方式更改键盘语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!