Skip to content

Commit

Permalink
Fix keyboard showing after the search box acquiring focus (#8227)
Browse files Browse the repository at this point in the history
* Fix keyboard showing after the search box acquiring focus
* Fix the underlying problem as described in the issue #7647
  • Loading branch information
dtcxzyw authored Apr 18, 2022
1 parent 671441b commit 127a273
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion app/src/main/java/org/schabi/newpipe/util/KeyboardUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,19 @@ public static void showKeyboard(final Activity activity, final EditText editText
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);
}
}
}

Expand Down

0 comments on commit 127a273

Please sign in to comment.