Vicky Leong
Vicky Leong

Reputation: 1258

Android soft keyboard stays open after confirming EditTextPreference dialog

Context: I'm working with settings using PreferenceFragment and Activity (Android 4.4.2 - API 19).

Problem: When clicking "OK" on the resulting dialog from EditTextPreference, the soft keyboard stays open.

Attempted Solution: Manually closing the soft keyboard onSharedPreferenceChanged inside the fragment. Only work if user changes and confirm the text. Not working if the user cancels. It also produces another problem namely: When user presses done, it changes the text, closes the keyboard, but leaves the dialog opened.

Question: How can I close both the keyboard and dialog when the user cancels, confirm, or presses done, which is a very normal and expected behavior.

Upvotes: 1

Views: 837

Answers (2)

Dmitry.S
Dmitry.S

Reputation: 1

I have had same issue. Check if you have android:windowSoftInputMode="stateHidden" attribute in your <activity> tag inside AndroidManifest.xml Try to remove this string. It helped in my case

Upvotes: 0

Mysterion231
Mysterion231

Reputation: 94

You can try this:

View view = this.getCurrentFocus();
if (view != null) {  
    InputMethodManager inputMethodManager = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
    inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
}

Force Android to hide the virtual keyboard using the InputMethodManager.

Upvotes: 1

Related Questions