以编程方式更改键盘输入语言 [英] Change Keyboard Input Language Programmatically

查看:234
本文介绍了以编程方式更改键盘输入语言的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个应用程序,我需要允许用户根据请求或默认情况下更改默认键盘中显示的输入键,例如,我可能会提示用户在开头选择默认语言和之后,每当使用默认键盘时,应用程序始终会显示所选语言的键盘键,

I am developing an application in which i need to allow the user to change the input keys shown in the default keyboard, upon request or by default, for example, i may prompt the user at the beginning to select the default language and after that, whenever the default keyboard is used, the app always displays the keys of the keyboard the selected language,

我知道这是可能的,因为在默认键盘应用中,当选择多个输入法时,长按空格键可以在运行时更改输入法,如果可以,那么我的要求也可以......

I know this is possible, because in default keyboard app, when multiple input methods are selected, then long pressing the spacebar allows to change the input methods at runtime, if this is possible then my requirement is also possible...

I不希望提示默认键盘,如下所示:

I dont want to prompt for default keyboard like following:

InputMethodManager imeManager = (InputMethodManager) getApplicationContext().getSystemService(INPUT_METHOD_SERVICE);
imeManager.showInputMethodPicker();

我不想改变语言环境并一直重启我的活动,如:

I dont want to change the locale and restart my activity all the time like:

Resources res = getBaseContext().getResources();
// Change locale settings in the app.
DisplayMetrics dm = res.getDisplayMetrics();
android.content.res.Configuration conf = res.getConfiguration();
conf.locale = new Locale("ru".toLowerCase());
res.updateConfiguration(conf, dm);
Log.i("inside onStart","after ever");   
setContentView(R.layout.activity_main);

我只想用我想要的语言显示键盘输入。

I just want to show the keyboard input in my desired language.

推荐答案

在这里做了一些研究之后找到了答案,首先你必须创建一个自定义键盘View,它扩展了keyboardView并在其中创建了静态键值变量喜欢

After doing some research here and there found the answer, first of all you have to create a custom keyboard View which extends keyboardView and 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);

这篇关于以编程方式更改键盘输入语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆