0

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?

Yaza
  • 195
  • 2
  • 10
  • 22
  • Have you test the answer's code, it seems your code is not complete. – York Shen Aug 07 '17 at 23:25
  • Hi York, thank you for your answer. But the code is in java and I thought maybe it's different in xamarin. I have tried to convert the code but that was not possible. I have found another example in xamarin, but it was with xamarin forms and I want to use the native controls. But now I was able to do it with what I have, but the only thing I don't see is a back button in the searchview. – Yaza Aug 08 '17 at 09:16
  • You could read this : https://stackoverflow.com/questions/44998483/searching-through-recyclerview-xamarin-droid/45011379#45011379 – York Shen Aug 09 '17 at 13:36

0 Answers0