1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2024-12-22 16:10:31 +00:00

Fix keyboard showing after the search box acquiring focus (#8227)

* Fix keyboard showing after the search box acquiring focus
* Fix the underlying problem as described in the issue #7647
This commit is contained in:
Yingwei Zheng 2022-04-18 22:05:42 +08:00 committed by GitHub
parent 671441bdf8
commit 127a27315e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -24,7 +24,19 @@ public final class KeyboardUtil {
if (editText.requestFocus()) {
final InputMethodManager imm = ContextCompat.getSystemService(activity,
InputMethodManager.class);
imm.showSoftInput(editText, InputMethodManager.SHOW_FORCED);
if (!imm.showSoftInput(editText, InputMethodManager.SHOW_FORCED)) {
/*
* Sometimes the keyboard can't be shown because Android's ImeFocusController is in
* a incorrect state e.g. when animations are disabled or the unfocus event of the
* previous view arrives in the wrong moment (see #7647 for details).
* The invalid state can be fixed by to re-focusing the editText.
*/
editText.clearFocus();
editText.requestFocus();
// Try again
imm.showSoftInput(editText, InputMethodManager.SHOW_FORCED);
}
}
}