Merge pull request #5365 from ByteHamster/fix-hiding-keyboard

Fix sometimes showing keyboard instead of hiding it
This commit is contained in:
ByteHamster 2021-08-28 13:23:42 +02:00 committed by GitHub
commit f8779fbba2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 2 deletions

View File

@ -6,6 +6,7 @@ import android.os.Bundle;
import android.provider.Settings;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import androidx.appcompat.app.ActionBar;
@ -141,9 +142,12 @@ public class PreferenceActivity extends AppCompatActivity implements SearchPrefe
finish();
} else {
InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
if (imm.isActive()) {
imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, InputMethodManager.HIDE_NOT_ALWAYS);
View view = getCurrentFocus();
//If no view currently has focus, create a new one, just so we can grab a window token from it
if (view == null) {
view = new View(this);
}
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
getSupportFragmentManager().popBackStack();
}
return true;