Skip to content

Commit e5b2fde

Browse files
authored
Hide Keyboard on IME_DONE (#38)
1 parent f02cda4 commit e5b2fde

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

lib/src/main/java/com/bytehamster/lib/preferencesearch/SearchPreferenceActionView.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import androidx.appcompat.app.AppCompatActivity;
55
import androidx.appcompat.widget.SearchView;
66
import android.util.AttributeSet;
7-
import android.view.View;
87
import androidx.fragment.app.FragmentManager;
98

109
public class SearchPreferenceActionView extends SearchView {

lib/src/main/java/com/bytehamster/lib/preferencesearch/SearchPreferenceFragment.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import android.view.LayoutInflater;
1111
import android.view.View;
1212
import android.view.ViewGroup;
13+
import android.view.inputmethod.EditorInfo;
1314
import android.view.inputmethod.InputMethodManager;
1415
import android.widget.EditText;
1516
import android.widget.ImageView;
@@ -101,6 +102,13 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
101102
viewHolder.recyclerView.setAdapter(adapter);
102103

103104
viewHolder.searchView.addTextChangedListener(textWatcher);
105+
viewHolder.searchView.setOnEditorActionListener((v, actionId, event) -> {
106+
if (actionId == EditorInfo.IME_ACTION_DONE) {
107+
hideKeyboard();
108+
return true;
109+
}
110+
return false;
111+
});
104112

105113
if (!searchConfiguration.isSearchBarEnabled()) {
106114
viewHolder.cardView.setVisibility(View.GONE);
@@ -208,6 +216,7 @@ private void hideKeyboard() {
208216
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
209217
if (view != null && imm != null) {
210218
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
219+
view.clearFocus();
211220
}
212221
}
213222

0 commit comments

Comments
 (0)