gpt4 book ai didi

android - 如何检测 TextView 中的键盘语言?

转载 作者:行者123 更新时间:2023-11-29 14:12:30 24 4
gpt4 key购买 nike

enter image description here

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获取有关 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;
}

关于android - 如何检测 TextView 中的键盘语言?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49449268/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com