Xamarin-MaterialSearchView 1.0.0

Cute library to implement SearchView in a Material Design Approach. Works from Android API 14 (ICS) and above.

Install-Package Xamarin-MaterialSearchView -Version 1.0.0
dotnet add package Xamarin-MaterialSearchView --version 1.0.0
<PackageReference Include="Xamarin-MaterialSearchView" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Xamarin-MaterialSearchView --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Basic example:

XML:
Layout:

<?xml version="1.0" encoding="UTF-8" ?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:background="@color/colorGray"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   android:orientation="vertical">
   <include layout="@layout/search_container" />
</LinearLayout>

search_container.xml

<?xml version="1.0" encoding="UTF-8" ?>
<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/toolbar_container"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="@color/colorPrimary" />

    <com.miguelcatalan.materialsearchview.MaterialSearchView
        android:id="@+id/search_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
</FrameLayout>

Menu:
menu_search.xml

<?xml version="1.0" encoding="UTF-8" ?>
<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"
    tools:context="com.domain.myApp.YourClassActivity">
    <item
        android:id="@+id/action_search"
        android:icon="@drawable/ic_action_action_search"
        android:orderInCategory="100"
        android:title="@string/search_title"
        app:showAsAction="always" />
</menu>

C#:

public partial class YourClassActivity : AppCompatActivity
{
    private MaterialSearchView SearchView;
    protected override void OnCreate(Bundle savedInstanceState)
    {

        SearchView = FindViewById<MaterialSearchView>(Resource.Id.search_view);

        SearchView.SetOnQueryTextListener(new MaterialSearchViewListener(this));

        //Optional to enable voice search
        //SearchView.SetVoiceSearch(true);        
    }

    public override bool OnCreateOptionsMenu(IMenu menu)
    {
        MenuInflater.Inflate(Resource.Menu.menu_search, menu);

        SearchView.SetMenuItem(menu.FindItem(Resource.Id.action_search));

        return true;
    }
}

public partial class YourClassActivity
{
    public class MaterialSearchViewListener : Java.Lang.Object, MaterialSearchView.IOnQueryTextListener
    {
        public bool OnQueryTextChange(string p0)
        {
            return true;
        }

        public bool OnQueryTextSubmit(string p0)
        {
            return true;
        }
    }
}

Basic example:

XML:
Layout:

<?xml version="1.0" encoding="UTF-8" ?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:background="@color/colorGray"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   android:orientation="vertical">
   <include layout="@layout/search_container" />
</LinearLayout>

search_container.xml

<?xml version="1.0" encoding="UTF-8" ?>
<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/toolbar_container"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="@color/colorPrimary" />

    <com.miguelcatalan.materialsearchview.MaterialSearchView
        android:id="@+id/search_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
</FrameLayout>

Menu:
menu_search.xml

<?xml version="1.0" encoding="UTF-8" ?>
<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"
    tools:context="com.domain.myApp.YourClassActivity">
    <item
        android:id="@+id/action_search"
        android:icon="@drawable/ic_action_action_search"
        android:orderInCategory="100"
        android:title="@string/search_title"
        app:showAsAction="always" />
</menu>

C#:

public partial class YourClassActivity : AppCompatActivity
{
    private MaterialSearchView SearchView;
    protected override void OnCreate(Bundle savedInstanceState)
    {

        SearchView = FindViewById<MaterialSearchView>(Resource.Id.search_view);

        SearchView.SetOnQueryTextListener(new MaterialSearchViewListener(this));

        //Optional to enable voice search
        //SearchView.SetVoiceSearch(true);        
    }

    public override bool OnCreateOptionsMenu(IMenu menu)
    {
        MenuInflater.Inflate(Resource.Menu.menu_search, menu);

        SearchView.SetMenuItem(menu.FindItem(Resource.Id.action_search));

        return true;
    }
}

public partial class YourClassActivity
{
    public class MaterialSearchViewListener : Java.Lang.Object, MaterialSearchView.IOnQueryTextListener
    {
        public bool OnQueryTextChange(string p0)
        {
            return true;
        }

        public bool OnQueryTextSubmit(string p0)
        {
            return true;
        }
    }
}

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
1.0.0 88 6/26/2019