开发者

Change Android KeyBoard language

How to change Android Keyboard language?

I have set below code to set language. I set different language from Settings and trying to set English language.

Locale.setDefault(Locale.ENGLISH);
Configuration config = getResources().getConfigura开发者_如何学Pythontion();
config.locale = Locale.ENGLISH;
getBaseContext().getResources().updateConfiguration(config, null);


Changing locale only changes the resources (e.g., strings, images, etc) to those defined for a specific locale in an app. To change the language supported by the keyboard, you have to make sure a proper input method is installed on the device (because the input method itself is also an app, it will change to a corresponding language).

For example, there is only English keyboard on Nexus S, if I need a keyboard that supports other language, I need to find a input method that supports that language, and install it.

To make sure the user have one, you can make some alert to take the users' attention, or bring them to the keyboard settings activity by ACTION_XXX_SETTINGS intent.


(API 24+): If you are using a TextView/EditText, then you can call TextView#setImeHintLocales(LocaleList)

textView.setImeHintLocales(new LocaleList(new Locale("zh", "CN")));

Note: This works on very few keyboards (at the time of writing, GBoard works and SwiftKey doesn't).

Note: If you want new "hint" to take effect immediately you need to call InputMethodManager#restartInput(View).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜