Need help with MaterialSearchView?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

MiguelCatalan
3.8K Stars 632 Forks Apache License 2.0 66 Commits 166 Opened issues

Description

Cute library to implement SearchView in a Material Design Approach

Services available

!
?

Need anything else?

Contributors list

# 36,638
Java
Groovy
35 commits
# 166,721
PHP
HTML
Android
playsto...
1 commit
# 81,746
Kotlin
polymor...
monads
carthag...
1 commit
# 76,863
Redux
Android
Kotlin
kotlin-...
1 commit
# 190,770
Java
Android
android...
HTML
1 commit
# 176,435
Flutter
flutter...
Dart
macOS
1 commit
# 4,479
Java
Android
novoda
Kotlin
1 commit
# 36,371
Java
Objecti...
popup-w...
React
1 commit

MaterialSearchView

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

sample sample

Get it on Google Play

Native version

Maybe it would be useful to take a look into the new official approach http://www.materialdoc.com/search-filter/

Usage

Add the dependencies to your gradle file:

javascript
    dependencies {
        compile 'com.miguelcatalan:materialsearchview:1.4.0'
    }
Add MaterialSearchView to your layout file along with the Toolbar (Add this block at the bottom of your layout, in order to display it over the rest of the view):
    
    

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

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

Add the search item into the menu file:

xml
    
Add define it in the onCreateOptionsMenu: ```java @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.menu_main, menu);
    MenuItem item = menu.findItem(R.id.action_search);
    searchView.setMenuItem(item);

return true;

}

Set the listeners:

```java MaterialSearchView searchView = (MaterialSearchView) findViewById(R.id.search_view); searchView.setOnQueryTextListener(new MaterialSearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String query) { //Do some magic return false; }

        @Override
        public boolean onQueryTextChange(String newText) {
            //Do some magic
            return false;
        }
    });

    searchView.setOnSearchViewListener(new MaterialSearchView.SearchViewListener() {
        @Override
        public void onSearchViewShown() {
            //Do some magic
        }

        @Override
        public void onSearchViewClosed() {
            //Do some magic
        }
    });

Use VoiceSearch

Allow/Disable it in the code:

java
    searchView.setVoiceSearch(true); //or false
Handle the response: ```java @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == MaterialSearchView.REQUESTVOICE && resultCode == RESULTOK) { ArrayList matches = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS); if (matches != null && matches.size() > 0) { String searchWrd = matches.get(0); if (!TextUtils.isEmpty(searchWrd)) { searchView.setQuery(searchWrd, false); } }
        return;
    }
    super.onActivityResult(requestCode, resultCode, data);
}
# Add suggestions
**Define them in the resources as a *string-array*:**
```xml
    
        Android
        iOS
        SCALA
        Ruby
        JavaScript
    

Add them to the object:

java
    searchView.setSuggestions(getResources().getStringArray(R.array.query_suggestions));

Style it!

    

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.