I am using a search-view element in my fragment to implement search feature.
<SearchView android:id="@+id/search_bar" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginTop="7dp" android:layout_marginLeft="7dp" android:layout_marginRight="7dp" android:layout_marginBottom="7dp" android:background="@color/white" />
The problem is only the search icon is clickable other area in the search bar is not clickable, when i click the icon only i can able to search.
Can you please help me to make the whole search area clickable.
By default the SearchView is 'iconified', which is displayed as a magnifying glass icon and only if the user clicks on the icon, then the edit field expands. To enable the user to click anywhere on the SearchView and expand the input field.
To make the SearchView expanded by default, call setIconifiedByDefault(false) on it when you initialise it (e.g. in onCreateOptionsMenu(..) or onPrepareOptionsMenu(..) ). I've found in most cases this will give it focus automatically, but if not simply call requestFocus() on it too.
This can be simply done by setting Iconified to false on OnClick of SearchView.
searchBar.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { searchBar.setIconified(false); } });
Reference: Eric Lui's answer
Hopefully it will help.
UPDATE:
You can also use it directly in your XML
app:iconifiedByDefault="false"
search_bar.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { search_bar.onActionViewExpanded(); } });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With