# SimpleSearchView **Repository Path**: dzcode8/SimpleSearchView ## Basic Information - **Project Name**: SimpleSearchView - **Description**: No description available - **Primary Language**: Android - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2021-08-09 - **Last Updated**: 2021-12-08 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # SimpleSearchView [![API](https://img.shields.io/badge/API-16%2B-brightgreen.svg?style=flat)](https://android-arsenal.com/api?level=16) [![Release](https://img.shields.io/github/release/Ferfalk/SimpleSearchView/all.svg?style=flat)](https://jitpack.io/#Ferfalk/SimpleSearchView) [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-SimpleSearchView-brightgreen.svg?style=flat)](https://android-arsenal.com/details/1/7287) A simple SearchView for Android based on Material Design * API 16+ *(Reveal animation for API 21 and above, fade animation otherwise)* * Two styles * Option to hide TabLayout automatically when it opens * Text and animations listeners * Customization options Card sample        Bar sample ## Download Add the JitPack repository to the build.gradle file: ```groovy allprojects { repositories { ... maven { url 'https://jitpack.io' } } } ``` Add the Gradle dependency: ```groovy implementation 'com.github.Ferfalk:SimpleSearchView:0.2.0' ``` ## Usage Add SimpleSearchView to your AppBarLayout: ```xml ``` [Setup with an MenuItem](#menuitem) or [Open manually](#open-and-close-manually) Setup the listener: *Return true to override default behaviour* ```java simpleSearchView.setOnQueryTextListener(new SimpleSearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String query) { Log.d("SimpleSearchView", "Submit:" + query); return false; } @Override public boolean onQueryTextChange(String newText) { Log.d("SimpleSearchView", "Text changed:" + newText); return false; } @Override public boolean onQueryTextCleared() { Log.d("SimpleSearchView", "Text cleared"); return false; } }); ``` ## Options ### MenuItem *Open when the MenuItem is clicked* Add the search item to the menu xml: ```xml ``` Setup the MenuItem : ```java @Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.main_menu, menu); MenuItem item = menu.findItem(R.id.action_search); searchView.setMenuItem(item); return true; } ``` ### TabLayout *Hides the TabLayout when the SimpleSearchView opens* Add it to the layout with a TabLayout: ```xml ``` Setup the TabLayout: ```java simpleSearchView.setTabLayout(findViewById(R.id.tabLayout)); ``` ### Open and close manually ```java simpleSearchView.showSearch(); simpleSearchView.closeSearch(); ``` ### OnBackPressed *Closes the SimpleSearchView automatically* ```java @Override public void onBackPressed() { if (searchView.onBackPressed()) { return; } super.onBackPressed(); } ``` ### Voice search ``` app:voiceSearch="true" ``` or ```java simpleSearchView.enableVoiceSearch(true); ``` Handle the result: *Will set the query automatically* ```java @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (searchView.onActivityResult(requestCode, resultCode, data)) { return; } super.onActivityResult(requestCode, resultCode, data); } ``` ### Style Bar style *(default)*: ``` app:type="bar" ``` Card style: ``` app:type="card" ``` ### Open and close listener ```java simpleSearchView.setOnSearchViewListener(new SimpleSearchView.SearchViewListener() { @Override public void onSearchViewShown() { Log.d("SimpleSearchView", "onSearchViewShown"); } @Override public void onSearchViewClosed() { Log.d("SimpleSearchView", "onSearchViewClosed"); } @Override public void onSearchViewShownAnimation() { Log.d("SimpleSearchView", "onSearchViewShownAnimation"); } @Override public void onSearchViewClosedAnimation() { Log.d("SimpleSearchView", "onSearchViewClosedAnimation"); } }); ``` ### Changing the reveal animation starting point ```java // Adding padding to the animation because of the hidden menu item Point revealCenter = simpleSearchView.getRevealAnimationCenter(); revealCenter.x -= DimensUtils.convertDpToPx(EXTRA_REVEAL_CENTER_PADDING, this); ``` ### Attributes ```xml ``` ## License Copyright (C) 2018 Fernando Augusto Heeren Falkiewicz Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.