如何获取用户键盘语言
how to get user keyboard language
我正在编写一个使用编辑文本的应用程序。我想知道用户在 oncreate 方法中输入的语言是什么,或者键盘输入类型何时更改。有没有办法设置一个监听器来获得这种变化?我找到的所有答案都是关于语言环境而不是关于输入语言的。我不想处理语言环境,语言环境对应用程序没有影响,输入语言有影响。
我使用了这个代码。
private void printInputLanguages() {
List<InputMethodInfo> ims = imm.getEnabledInputMethodList();
for (InputMethodInfo method : ims) {
List<InputMethodSubtype> submethods = imm
.getEnabledInputMethodSubtypeList(method, true);
for (InputMethodSubtype submethod : submethods) {
if (submethod.getMode().equals("keyboard")) {
String currentLocale =
submethod.getLocale();
tv.setText(currentLocale);
Log.i("sara", "Available input method locale: "
+ currentLocale);
}
}
}
}
和这些代码,但是 none 没有帮助。
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
InputMethodSubtype ims = imm.getCurrentInputMethodSubtype();
String localeString = ims.getLocale();
Locale locale = new Locale(localeString);
String currentLanguage = locale.getDisplayLanguage();
感谢您的帮助。
没有办法做到这一点。键盘的输入语言没有报告给OS——实际上Android没有输入语言的概念。这是第 3 方键盘制造商提出的想法。所以实际上键盘可以用任何语言打字,而 OS 不会知道。
我正在编写一个使用编辑文本的应用程序。我想知道用户在 oncreate 方法中输入的语言是什么,或者键盘输入类型何时更改。有没有办法设置一个监听器来获得这种变化?我找到的所有答案都是关于语言环境而不是关于输入语言的。我不想处理语言环境,语言环境对应用程序没有影响,输入语言有影响。 我使用了这个代码。
private void printInputLanguages() {
List<InputMethodInfo> ims = imm.getEnabledInputMethodList();
for (InputMethodInfo method : ims) {
List<InputMethodSubtype> submethods = imm
.getEnabledInputMethodSubtypeList(method, true);
for (InputMethodSubtype submethod : submethods) {
if (submethod.getMode().equals("keyboard")) {
String currentLocale =
submethod.getLocale();
tv.setText(currentLocale);
Log.i("sara", "Available input method locale: "
+ currentLocale);
}
}
}
}
和这些代码,但是 none 没有帮助。
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
InputMethodSubtype ims = imm.getCurrentInputMethodSubtype();
String localeString = ims.getLocale();
Locale locale = new Locale(localeString);
String currentLanguage = locale.getDisplayLanguage();
感谢您的帮助。
没有办法做到这一点。键盘的输入语言没有报告给OS——实际上Android没有输入语言的概念。这是第 3 方键盘制造商提出的想法。所以实际上键盘可以用任何语言打字,而 OS 不会知道。