I want to add a search just like described in this article:
Implementing SearchView as per the material design guidelines
But I'm not able to do that. This is what I have so far:
menu.xml:
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/action_search"
android:title="Search"
android:icon="@drawable/abc_ic_search_api_mtrl_alpha"
android:showAsAction="ifRoom|collapseActionView"
android:actionViewClass="android.support.v7.widget.SearchView" />
<item
android:id="@+id/menu_signOut"
android:showAsAction="never"
android:title="Sign out" />
<item
android:id="@+id/menu_refresh"
android:showAsAction="never"
android:title="Refresh data" />
</menu>
Code in activity.cs
public override bool OnCreateOptionsMenu(IMenu menu)
{
MenuInflater.Inflate(Resource.Menu.bookingList_menus, menu);
var item = menu.FindItem(Resource.Id.action_search);
var searchItem = MenuItemCompat.GetActionView(item);
_searchView = searchItem.JavaCast<Android.Support.V7.Widget.SearchView>();
_searchView.QueryTextChange += (s, e) =>
{
};
_searchView.QueryTextSubmit += (s, e) =>
{
//TODO: Do something fancy when search button on keyboard is pressed
Toast.MakeText(this, "Searched for: " + e.Query, ToastLength.Short).Show();
e.Handled = true;
};
return true;
}
The searchview is visible, but it doesn't animate like in that article and it doesn't change the backcolor to white. What I also mis, is that it doesn't focus the search view when I click on search in the toolbar.
I also want to use only the native controls.
Am I missing here something?