8

on a multi-lang device, where user can switch the keyboard/language. how to detect what keyboard the user is using? for example, if the user has arabic and english keyboards. how to detect if he is using the arabic or the english one?

is there a way OTHER than checking the input and determine which language is he typing?

4

1 回答 1

10

通过搜索 react native 文档https://facebook.github.io/react-native/docs/keyboard.html没有提供键盘实际语言的属性或函数,但您可以通过实现一个在您的 java 或 Objective-C 代码中的函数

您可以在此处了解如何添加您的个人本机代码并将其用于本机反应: https ://facebook.github.io/react-native/docs/native-modules-android.html

然后只需将此方法添加到您的“MyCustomKeyboard”类(java)上:

@ReactMethod
public String getKeyboardLanguage() {
  InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
  InputMethodSubtype ims = imm.getCurrentInputMethodSubtype();
  String locale = ims.getLocale();
  return locale;
}
于 2018-06-23T18:29:53.980 回答