Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

How to add searchview for android material design

$
0
0

Hi there,

I want to add a search just like described in this article:

https://stackoverflow.com/questions/30369246/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.

Am I missing here something?


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>