检测文本输入上的活动键盘语言 - 反应原生

Zor*_*rox 5 react-native

在多语言设备上,用户可以在其中切换键盘/语言.如何检测用户使用的键盘?例如,如果用户有阿拉伯语和英语键盘.如何检测他是否使用阿拉伯语或英语?

有没有办法其他不是检查输入,并确定哪一种语言,他打字?

Dje*_*iss 9

通过搜索本机文档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;
}
Run Code Online (Sandbox Code Playgroud)