Xamarin-MaterialSearchView 2.0.0.1

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

Install-Package Xamarin-MaterialSearchView -Version 2.0.0.1
dotnet add package Xamarin-MaterialSearchView --version 2.0.0.1
<PackageReference Include="Xamarin-MaterialSearchView" Version="2.0.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Xamarin-MaterialSearchView --version 2.0.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Xamarin-MaterialSearchView, 2.0.0.1"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install Xamarin-MaterialSearchView as a Cake Addin
#addin nuget:?package=Xamarin-MaterialSearchView&version=2.0.0.1

// Install Xamarin-MaterialSearchView as a Cake Tool
#tool nuget:?package=Xamarin-MaterialSearchView&version=2.0.0.1
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" ?>
<com.google.android.material.appbar.AppBarLayout
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/toolbar_container"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <androidx.appcompat.widget.Toolbar
            android:id="@+id/toolbar"
            app:theme="@style/ToolBarStyle"
            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>

</com.google.android.material.appbar.AppBarLayout>

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" ?>
<com.google.android.material.appbar.AppBarLayout
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/toolbar_container"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <androidx.appcompat.widget.Toolbar
            android:id="@+id/toolbar"
            app:theme="@style/ToolBarStyle"
            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>

</com.google.android.material.appbar.AppBarLayout>

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;
        }
    }
}

Release Notes

Upgraded to AndroidX.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
2.0.0.1 224 8/12/2020
2.0.0 157 7/24/2020
1.0.0 329 6/26/2019