Fix sometimes showing keyboard instead of hiding it

This commit is contained in:
ByteHamster 2021-08-28 12:23:33 +02:00
parent ddae5e2278
commit c73ca12e62
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.provider.Settings;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View;
import android.view.inputmethod.InputMethodManager; import android.view.inputmethod.InputMethodManager;
import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.ActionBar;
@ -141,9 +142,12 @@ public class PreferenceActivity extends AppCompatActivity implements SearchPrefe
finish(); finish();
} else { } else {
InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE); InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
if (imm.isActive()) { View view = getCurrentFocus();
imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, InputMethodManager.HIDE_NOT_ALWAYS); //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(); getSupportFragmentManager().popBackStack();
} }
return true; return true;