Skip to content

Commit

Permalink
Hide Keyboard on IME_DONE (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sagar0-0 authored Feb 15, 2025
1 parent f02cda4 commit e5b2fde
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.SearchView;
import android.util.AttributeSet;
import android.view.View;
import androidx.fragment.app.FragmentManager;

public class SearchPreferenceActionView extends SearchView {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.ImageView;
Expand Down Expand Up @@ -101,6 +102,13 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
viewHolder.recyclerView.setAdapter(adapter);

viewHolder.searchView.addTextChangedListener(textWatcher);
viewHolder.searchView.setOnEditorActionListener((v, actionId, event) -> {
if (actionId == EditorInfo.IME_ACTION_DONE) {
hideKeyboard();
return true;
}
return false;
});

if (!searchConfiguration.isSearchBarEnabled()) {
viewHolder.cardView.setVisibility(View.GONE);
Expand Down Expand Up @@ -208,6 +216,7 @@ private void hideKeyboard() {
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
if (view != null && imm != null) {
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
view.clearFocus();
}
}

Expand Down

0 comments on commit e5b2fde

Please sign in to comment.