I am building a chat application just like Whatsapp. I have build the search functionality successfully in my application using the SearchView
in the ActionBar
. This is what I have done so far:
Instead of this I want the SearchView
with navigation up and down arrows (like in Whatsapp) when I click on the search button. This is what I want to achieve:
Here is my code for the Search button:
// SearchView
SearchView searchView = (SearchView) menu.findItem(R.id.action_search)
.getActionView();
searchView.setQueryHint("Search...");
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
adapter.filter(query);
return false;
}
@Override
public boolean onQueryTextChange(String newText) {
adapter.filter(newText);
return true;
}
});
This is the xml
file in my menu folder:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" >
<item
android:id="@+id/action_settings"
android:orderInCategory="100"
android:title="@string/action_settings"
app:showAsAction="never"/>
<item android:id="@+id/action_search"
android:title="@string/action_search"
app:showAsAction="never|collapseActionView"
app:actionViewClass="android.support.v7.widget.SearchView" />
</menu>
Please tell me how to achieve this. Thanks