问题:设置默认输入法为第三方输入法,切换语言后输入法变为其他输入法
原因(Android 11):
frameworks/base/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java
private void resetDefaultImeLocked(Context context) {
// Do not reset the default (current) IME when it is a 3rd-party IME
if (mCurMethodId != null && !mMethodMap.get(mCurMethodId).isSystem()) {
return;
}
final List<InputMethodInfo> suitableImes = InputMethodUtils.getDefaultEnabledImes(
context, mSettings.getEnabledInputMethodListLocked());
if (suitableImes.isEmpty()) {
Slog.i(TAG, "No default found");
return;
}
final InputMethodInfo defIm = suitableImes.get(0);
if (DEBUG) {
Slog.i(TAG, "Default found, using " + defIm.getId());
}
setSelectedInputMethodAndSubtypeLocked(defIm, NOT_A_SUBTYPE_ID, false);
}
由于切语言后,非系统输入法不会被设置,删除以下代码
if (mCurMethodId != null && !mMethodMap.get(mCurMethodId).isSystem()) {
return;
}
https://blog.csdn.net/nei504293736/article/details/51599733(android 切换系统语言,输入法也随之切换)