binding.etShortText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus) {
String language = getKeyboardLanguage();
Log.d("language is", language);
binding.txtDetectLang.setText(language);
}
}
});
}
private String getKeyboardLanguage() {
InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
InputMethodSubtype inputMethodSubtype = inputMethodManager.getCurrentInputMethodSubtype();
return inputMethodSubtype.getLocale();
}
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
InputMethodSubtype ims = imm.getCurrentInputMethodSubtype();
String locale = ims.getLocale();
//get Locale object first
Locale locale = new Locale(localeString);
//then get the display language from locale object.
String currentLanguage = locale.getDisplayLanguage();
//Also note that this method is deprecated in API 24. For API 24 or further use getLanguageTag() method.
您可以尝试使用此代码来获取“当前键盘语言”区域代码。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句