4

I have two SearchViews in my toolbar and I would like to enable the blinking cursor so that I can see which searchView I'm currently typing in. When I start typing in the SearchView no cursor is available. When I type some more and then touch the text I typed, a blue pointing shape points to the clicked text location -- but no cursor appears.

How do I enable the black blinking rectangular line cursor programmatically?

Some things I've tried:

  1. Changing cursor color incase it was invisible - StackOverFlow
  2. searchView.setFocusable(), searchView.requestFromTouch()

Maybe its something wrong with setting up my searchView? Heres my setupSearchView code:

SearchManager searchManager = (SearchManager)getActivity().getSystemService(Context.SEARCH_SERVICE);
searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName()));
searchView.setIconified(false);
searchView.setonActionExpanded();
searchView.setQueryHint(hint);
searchView.setFocusable(true);
Community
  • 1
  • 1
Kevin.Lam
  • 289
  • 1
  • 4
  • 16

2 Answers2

0
   SearchView.SearchAutoComplete searchTextView =  mSearchView.findViewById(R.id.search_src_text);
        try {
            Field mCursorDrawableRes = TextView.class.getDeclaredField("mCursorDrawableRes");
            mCursorDrawableRes.setAccessible(true);
            mCursorDrawableRes.set(searchTextView, 0);
            //This sets the cursor resource ID to 0 or @null which will make it visible on white background
        } catch (Exception e) {
            e.printStackTrace();
        }
Pawan Chaurasiya
  • 881
  • 2
  • 16
  • 30
0

I also had this problem and tried everything, until I changed the InputType (TYPE_TEXT_VARIATION_NORMAL) of the SearchView. After changing the InputType to TYPE_TEXT_VARIATION_FILTER I got the cursor back and the soft keyboard is shown. So please check if the input type is the problem. The code below is from a Xamarin Android project, but it should be similar in Java.

SearchView.InputType = (int)InputTypes.TextVariationFilter;
Kjube
  • 31
  • 4