如何检测textview中的键盘语言?
在这里输入图像描述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(); 返回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.
您可以尝试使用此代码获取当前键盘语言区域代码。
我想你想获得软件键盘语言的语言。 您可以使用InputMethodManager获取有关Android中输入类型的信息。
private String getKeyboardLanguage(){
String language = "";
// This will give you to access input method manager
InputMethodManager im = (InputMethodManager)Context.getSystemService(Context.INPUT_METHOD_SERVICE);
// Input methods has several subtypes, this will return the active one
InputMethodSubtype subtype = im.getCurrentInputMethodSubtype();
if(subtype != null){ // subtype can be null
// Returns BCP-47 Language Tag or returns empty string if not specified
language = getLanguageTag();
}
return language;
}
链接地址: http://www.djcxy.com/p/16675.html
上一篇: How to detect keyboard language in textview?
下一篇: after some edittext input automatically disable keypad in android