{"id":3527,"url":"https://github.com/mancj/MaterialSearchBar","last_synced_at":"2025-08-03T20:32:37.326Z","repository":{"id":43721577,"uuid":"63781933","full_name":"mancj/MaterialSearchBar","owner":"mancj","description":"Material Design Search Bar for Android","archived":false,"fork":false,"pushed_at":"2022-07-07T13:40:02.000Z","size":2424,"stargazers_count":2031,"open_issues_count":84,"forks_count":332,"subscribers_count":44,"default_branch":"master","last_synced_at":"2024-11-21T02:33:27.036Z","etag":null,"topics":["android","gradle","material","search","searchbar","ui","view"],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mancj.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-07-20T13:02:53.000Z","updated_at":"2024-11-18T14:16:37.000Z","dependencies_parsed_at":"2022-08-12T10:42:10.354Z","dependency_job_id":null,"html_url":"https://github.com/mancj/MaterialSearchBar","commit_stats":null,"previous_names":[],"tags_count":23,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mancj%2FMaterialSearchBar","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mancj%2FMaterialSearchBar/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mancj%2FMaterialSearchBar/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mancj%2FMaterialSearchBar/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mancj","download_url":"https://codeload.github.com/mancj/MaterialSearchBar/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228567009,"owners_count":17937983,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","gradle","material","search","searchbar","ui","view"],"created_at":"2024-01-05T20:16:44.038Z","updated_at":"2024-12-07T05:30:40.148Z","avatar_url":"https://github.com/mancj.png","language":"Java","readme":"\n# Material SearchBar Android\nMaterial Design Search Bar for Android\n[![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-MaterialSearchBar-orange.svg?style=flat)](http://android-arsenal.com/details/1/4158)\n[![](https://jitpack.io/v/mancj/MaterialSearchBar.svg)](https://jitpack.io/#mancj/MaterialSearchBar)\n\n----------\nThis beautiful and easy to use library will help to add Lollipop Material Design SearchView in your project.\n\n\u003cimg src=\"/art/preview.gif\" width=\"400\"\u003e\n\u003cimg src=\"/art/pv1.png\" width=\"400\"\u003e\n\u003cimg src=\"/art/pv2.png\" width=\"400\"\u003e\n\u003cimg src=\"/art/pv3.png\" width=\"400\"\u003e\n\u003cimg src=\"/art/pv4.png\" width=\"400\"\u003e\n\u003cimg src=\"/art/pv5.png\" width=\"400\"\u003e\n\n----------\n\n# See our [Wiki](https://github.com/mancj/MaterialSearchBar/wiki)\n\n\n# How to use\n\n**to include SearchBar to your project:**\n\n add this code to the the project level build.gradle file\n\n```gradle\nallprojects {\n\trepositories {\n\t\t...\n\t\tmaven { url \"https://jitpack.io\" }\n\t}\n}\n```\n\nadd the dependency to the the app level build.gradle file\n\n```gradle\ndependencies {\n\timplementation 'com.github.mancj:MaterialSearchBar:X.X.X'\n}\n\n```\n[![](https://jitpack.io/v/mancj/MaterialSearchBar.svg)](https://jitpack.io/#mancj/MaterialSearchBar)\n\nthen add SearchBar to your activity:\n\n```xml\n\u003ccom.mancj.materialsearchbar.MaterialSearchBar\n    style=\"@style/MaterialSearchBarLight\"\n    app:mt_speechMode=\"true\"\n    app:mt_hint=\"Custom hint\"\n    app:mt_maxSuggestionsCount=\"10\"\n    android:layout_width=\"match_parent\"\n    android:layout_height=\"wrap_content\"\n    android:id=\"@+id/searchBar\" /\u003e\n```\n\n----------\n\n**MaterialSearchBar has the following xml attributes:**\n\n| Attribute           | Description                                                                           |\n|---------------------|---------------------------------------------------------------------------------------|\n| mt_speechMode          | if set to true, microphone icon will be displayed instead of search icon    \t \t |\n| mt_maxSuggestionsCount | specifies the max number of search queries stored                                     |\n| mt_navIconEnabled      | set navigation icon enabled                                                           |\n| mt_roundedSearchBarEnabled | use capsule shaped searchbar on v21+ and revert to default on lower               |\n| mt_dividerColor        | set the colors of the suggestion and menu dividers   \t\t\t\t |\n| mt_searchBarColor      | set the main color of the searchbar                                                   |\n| mt_menuIconDrawable    | set drawable of the menu icon                                                         |\n| mt_searchIconDrawable  | set drawable of the search icon when speech mode is false                             |\n| mt_speechIconDrawable  | set drawable of the speech icon when speech mode is true                              |\n| mt_backIconDrawable    | set drawable of the back arrow icon                                                   |\n| mt_clearIconDrawable   | set drawable of the clear icon                                                        |\n| mt_navIconTint         | set tint color of nav/back animated icon                                              |\n| mt_menuIconTint        | set tint color of the menu icon                                                       |\n| mt_searchIconTint      | set tint color search/speech icon                                                     |\n| mt_backIconTint        | set tint color of the back arrow icon                                                 |\n| mt_clearIconTint       | set tint color of the clear icon                                                      |\n| mt_navIconUseTint      | should the animated nav icon use tint color                                           |\n| mt_menuIconUseTint     | should the menu icon use the tint color                                               |\n| mt_searchIconUseTint   | should the search/speech icon use the tint color                                      |\n| mt_backIconUseTint     | should the back icon use the tint color                                               |\n| mt_clearIconUseTint    | should the clear icon use the tint color                                              |\n| mt_hint                | set the text of the hint when the searchbar is focused and search query is empty      |\n| mt_placeholder         | set the placeholder text when the MaterialSearchBar is not focused                    |\n| mt_textColor           | set text color                                                                        |\n| mt_hintColor           | set hint color                                                                        | \n| mt_placeholderColor    | set placeholder color                                                                 |\n| mt_textCursorTint      | set text cursors tint                                                                 |\n| mt_highlightedTextColor | set the text highlight tint color                                                    |\n\n----------\n**public methods:**\n\n - `addTextChangeListener(TextWatcher textWatcher)`\n - `clearSuggestions()`\n - `closeSearch()`\n - `openSearch()`\n - `getLastSuggestions()`\n - `getMenu()`\n - `getText()`\n - `hideSuggestionList()`\n - `inflateMenu(int menuResource)`\n - `inflateMenu(int menuResource, int icon)`\n - `isSearchOpened()`\n - `isSpeechModeEnabled()`\n - `isSuggestionsVisible()`\n - `setArrowIcon(int arrowIconResId)`\n - `setArrowIconTint(int arrowIconTint)`\n - `setCardViewElevation(int elevation)`\n - `setClearIcon(int clearIconResId)`\n - `setClearIconTint(int clearIconTint)`\n - `setCustomSuggestionAdapter(SuggestionsAdapter suggestionAdapter)`\n - `setDividerColor(int dividerColor)`\n - `setHint(CharSequence hintText)`\n - `setIconRippleStyle(boolean borderlessRippleEnabled)`\n - `setLastSuggestions(List suggestions)`\n - `setMaxSuggestionCount(int maxSuggestionsCount)`\n - `setMenuDividerEnabled(boolean menuDividerEnabled)`\n - `setMenuIcon(int menuIconResId)`\n - `setMenuIconTint(int menuIconTint)`\n - `setNavButtonEnabled(boolean navButtonEnabled)`\n - `setNavIconTint(int navIconTint)`\n - `setOnSearchActionListener(OnSearchActionListener onSearchActionListener)`\n - `setPlaceHolder(CharSequence placeholder)`\n - `setPlaceHolderColor(int placeholderColor)`\n - `setRoundedSearchBarEnabled(boolean roundedSearchBarEnabled)`\n - `setSearchIcon(int searchIconResId)`\n - `setSearchIconTint(int searchIconTint)`\n - `setSpeechModeEnabled(boolean speechMode)`\n - `setSuggestionsClickListener(SuggestionsAdapter.OnItemViewClickListener listener)`\n - `setText(String text)`\n - `setTextColor(int textColor)`\n - `setTextHighlightColor(int highlightedTextColor)`\n - `setTextHintColor(int hintColor)`\n - `showSuggestions()`\n - `updateLastSuggestions(List suggestions)`\n\n----------\n**Styling Material SearchBar**\n\n**Custom Style - styles.xml**\nCreate a custom style and use one of the provided styles as the parent.\n\n```xml\nProvided Styles are: MaterialSearchBarLight and MaterialSearchBarDark\n\nExample:\n\u003cstyle name=\"MyCustomTheme\" parent=\"MaterialSearchBarLight\"\u003e\n     \u003citem name=\"mt_searchBarColor\"\u003e@color/searchBarPrimaryColor\u003c/item\u003e\n            \u003citem name=\"mt_dividerColor\"\u003e@color/searchBarDividerColor\u003c/item\u003e\n            \u003citem name=\"mt_navIconTint\"\u003e@color/searchBarNavIconTintColor\u003c/item\u003e\n            \u003citem name=\"mt_searchIconTint\"\u003e@color/searchBarSearchIconTintColor\u003c/item\u003e\n            \u003citem name=\"mt_clearIconTint\"\u003e@color/searchBarClearIconTintColor\u003c/item\u003e\n            \u003citem name=\"mt_menuIconTint\"\u003e@color/searchBarMenuIconTintColor\u003c/item\u003e\n            \u003citem name=\"mt_backIconTint\"\u003e@color/searchBarBackIconTintColor\u003c/item\u003e\n            \u003citem name=\"mt_textCursorTint\"\u003e@color/searchBarCursorColor\u003c/item\u003e\n            \u003citem name=\"mt_textColor\"\u003e@color/searchBarTextColor\u003c/item\u003e\n            \u003citem name=\"mt_hintColor\"\u003e@color/searchBarHintColor\u003c/item\u003e\n            \u003citem name=\"mt_placeholderColor\"\u003e@color/searchBarPlaceholderColor\u003c/item\u003e\n            \u003citem name=\"mt_highlightedTextColor\"\u003e@color/searchBarTextHighlightColor\u003c/item\u003e\n\u003c/style\u003e\n```\n**OR**\n\n**Custom Colors - colors.xml** \nSimply set/change these colors(or some) and you have your custom style.\n```xml\n    //Material SearchBar Light Theme Colors\n        \u003ccolor name=\"searchBarIconColor\"\u003e#3a3a3a\u003c/color\u003e\n        //Base\n        \u003ccolor name=\"searchBarPrimaryColor\"\u003e#FFFFFF\u003c/color\u003e\n        \u003ccolor name=\"searchBarCursorColor\"\u003e#8000a1ff\u003c/color\u003e\n        \u003ccolor name=\"searchBarDividerColor\"\u003e#1F000000\u003c/color\u003e\n    \n        //Icons\n        \u003ccolor name=\"searchBarNavIconTintColor\"\u003e@color/searchBarIconColor\u003c/color\u003e\n        \u003ccolor name=\"searchBarMenuIconTintColor\"\u003e@color/searchBarIconColor\u003c/color\u003e\n        \u003ccolor name=\"searchBarSearchIconTintColor\"\u003e@color/searchBarIconColor\u003c/color\u003e\n        \u003ccolor name=\"searchBarClearIconTintColor\"\u003e@color/searchBarIconColor\u003c/color\u003e\n        \u003ccolor name=\"searchBarBackIconTintColor\"\u003e@color/searchBarIconColor\u003c/color\u003e\n    \n        //Text\n        \u003ccolor name=\"searchBarTextColor\"\u003e#DE000000\u003c/color\u003e\n        \u003ccolor name=\"searchBarHintColor\"\u003e#42000000\u003c/color\u003e\n        \u003ccolor name=\"searchBarPlaceholderColor\"\u003e#8A000000\u003c/color\u003e\n        \u003ccolor name=\"searchBarTextHighlightColor\"\u003e#8000a1ff\u003c/color\u003e\n    \n        //Base\n        \u003ccolor name=\"searchBarPrimaryColorDark\"\u003e#303030\u003c/color\u003e\n        \u003ccolor name=\"searchBarDividerColorDark\"\u003e#1FFFFFFF\u003c/color\u003e\n    \n        //Material SearchBar Dark Theme Colors\n        \u003ccolor name=\"searchBarIconColorDark\"\u003e#00a1ff\u003c/color\u003e\n        //Icons\n        \u003ccolor name=\"searchBarNavIconTintColorDark\"\u003e@color/searchBarIconColorDark\u003c/color\u003e\n        \u003ccolor name=\"searchBarMenuIconTintColorDark\"\u003e@color/searchBarIconColorDark\u003c/color\u003e\n        \u003ccolor name=\"searchBarSearchIconTintColorDark\"\u003e@color/searchBarIconColorDark\u003c/color\u003e\n        \u003ccolor name=\"searchBarClearIconTintColorDark\"\u003e@color/searchBarIconColorDark\u003c/color\u003e\n        \u003ccolor name=\"searchBarBackIconTintColorDark\"\u003e@color/searchBarIconColorDark\u003c/color\u003e\n    \n        //Text\n        \u003ccolor name=\"searchBarTextColorDark\"\u003e#DEFFFFFF\u003c/color\u003e\n        \u003ccolor name=\"searchBarHintColorDark\"\u003e#42FFFFFF\u003c/color\u003e\n        \u003ccolor name=\"searchBarPlaceholderColorDark\"\u003e#8AFFFFFF\u003c/color\u003e\n        \u003ccolor name=\"searchBarTextHighlightColorDark\"\u003e#BF00a1ff\u003c/color\u003e\n```\n----------\nTo save search queries when the activity is destroyed, use the method `searchBar.getLastSuggestions()` and then, to restore them use `searchBar.setLastSuggestions(List\u003cString\u003e);` as shown in the example below\n\n# Example\n\nHere is a simple example of using MaterialSearchBar\n\n```java\nprivate List\u003cString\u003e lastSearches;\nprivate MaterialSearchBar searchBar;\n\n@Override\nprotected void onCreate(Bundle savedInstanceState) {\n    super.onCreate(savedInstanceState);\n    setContentView(R.layout.activity_main);\n\n    searchBar = (MaterialSearchBar) findViewById(R.id.searchBar);\n    searchBar.setHint(\"Custom hint\");\n    searchBar.setSpeechMode(true);\n    //enable searchbar callbacks\n    searchBar.setOnSearchActionListener(this);\n    //restore last queries from disk\n    lastSearches = loadSearchSuggestionFromDisk();\n    searchBar.setLastSuggestions(list);\n    //Inflate menu and setup OnMenuItemClickListener\n    searchBar.inflateMenu(R.menu.main);\n    searchBar.getMenu().setOnMenuItemClickListener(this);\n}\n\n@Override\nprotected void onDestroy() {\n    super.onDestroy();\n    //save last queries to disk\n    saveSearchSuggestionToDisk(searchBar.getLastSuggestions());\n}\n\n@Override\npublic void onSearchStateChanged(boolean enabled) {\n    String s = enabled ? \"enabled\" : \"disabled\";\n    Toast.makeText(MainActivity.this, \"Search \" + s, Toast.LENGTH_SHORT).show();\n}\n\n@Override\npublic void onSearchConfirmed(CharSequence text) {\n    startSearch(text.toString(), true, null, true);\n}\n\n@Override\npublic void onButtonClicked(int buttonCode) {\n    switch (buttonCode){\n        case MaterialSearchBar.BUTTON_NAVIGATION:\n            drawer.openDrawer(Gravity.LEFT);\n            break;\n        case MaterialSearchBar.BUTTON_SPEECH:\n            openVoiceRecognizer();\n    }\n}\n```\n\n\nMore [Examples](https://github.com/mancj/MaterialSearchBar/tree/master/app/src/main/java/com/mancj/example)\n","funding_links":[],"categories":["SearchView","Libraries"],"sub_categories":["GUI"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmancj%2FMaterialSearchBar","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmancj%2FMaterialSearchBar","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmancj%2FMaterialSearchBar/lists"}