0

I have a simple search input with minor customizations. I previously compiled against Android 6 and behavior was as expected:

  • Focus on the control
  • Keyboard comes up
  • etc.

When compiling against Android 7.1 (API 25), my SearchView(s) start behaving weirdly.

  • They have no Metro Style bottom border
  • They do not accept focus
  • Do not open keyboard
  • etc

I migrated from android.support.v7.widget.SearchView to android.widget.SearchView to see if that fixed the problem.

bpylearner
  • 507
  • 4
  • 12

2 Answers2

2

Apparently some internals of the View/Control have changed so the focus behavior has changed as well:

Instead of setting

searchView.ClearFocus();
searchView.Focusable = false;

(Apparently ClearFocus() was needed to keep the keyboard from popping up all the time.)

I now set

searchView.SetIconifiedByDefault(false);
searchView.Iconified = false;
searchView.RequestFocusFromTouch();

to have it expanded by default and accept inputs again.

Original helping hint was buried here:

https://stackoverflow.com/a/29876075/5872586

Hope this saves somebody some time!

PS: If somebody has an explanation of what's really going on please share your knowledge and I will accept yours as answer.

Community
  • 1
  • 1
bpylearner
  • 507
  • 4
  • 12
0

Here is all my code working with android.support.v7.widget.SearchView

    binding.searchView.setIconified(false);
    binding.searchView.clearFocus();

    EditText searchField = (EditText)
            binding.searchView.findViewById(android.support.v7.appcompat.R.id.search_src_text);

    searchField.setFocusableInTouchMode(true);
    searchField.requestFocus();
HuyTTQ
  • 388
  • 3
  • 7