[英]Change Android KeyBoard language
How to change Android Keyboard language?如何更改 Android 键盘语言?
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().getConfiguration();
config.locale = Locale.ENGLISH;
getBaseContext().getResources().updateConfiguration(config, null);
Changing locale
only changes the resources
(eg, strings, images, etc) to those defined for a specific locale
in an app.更改
locale
只会将resources
(例如字符串、图像等)更改为为应用程序中的特定locale
定义的resources
。 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).要更改
keyboard
支持的语言,您必须确保设备上安装了正确的input method
(因为输入法本身也是一个应用程序,它会更改为相应的语言)。
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.例如,
Nexus S
上只有英文键盘,如果我需要一个支持其他语言的键盘,我需要找到一个支持该语言的input method
,并安装它。
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.为了确保用户有一个,您可以发出一些警报以引起用户的注意,或者通过
ACTION_XXX_SETTINGS
意图将他们带到键盘设置活动。
(API 24+): If you are using a TextView
/ EditText
, then you can call TextView#setImeHintLocales(LocaleList) (API 24+):如果您使用的是
TextView
/ EditText
,那么您可以调用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).注意:这适用于很少的键盘(在撰写本文时,GBoard 有效而 SwiftKey 无效)。
Note: If you want new "hint" to take effect immediately you need to call InputMethodManager#restartInput(View)
.注意:如果您希望新的“提示”立即生效,您需要调用
InputMethodManager#restartInput(View)
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.