Skip to content

Commit 127a273

Browse files
authored
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
1 parent 671441b commit 127a273

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

app/src/main/java/org/schabi/newpipe/util/KeyboardUtil.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,19 @@ public static void showKeyboard(final Activity activity, final EditText editText
2424
if (editText.requestFocus()) {
2525
final InputMethodManager imm = ContextCompat.getSystemService(activity,
2626
InputMethodManager.class);
27-
imm.showSoftInput(editText, InputMethodManager.SHOW_FORCED);
27+
if (!imm.showSoftInput(editText, InputMethodManager.SHOW_FORCED)) {
28+
/*
29+
* Sometimes the keyboard can't be shown because Android's ImeFocusController is in
30+
* a incorrect state e.g. when animations are disabled or the unfocus event of the
31+
* previous view arrives in the wrong moment (see #7647 for details).
32+
* The invalid state can be fixed by to re-focusing the editText.
33+
*/
34+
editText.clearFocus();
35+
editText.requestFocus();
36+
37+
// Try again
38+
imm.showSoftInput(editText, InputMethodManager.SHOW_FORCED);
39+
}
2840
}
2941
}
3042

0 commit comments

Comments
 (0)