Original address: www.apkbus.com/blog-927916…

[] () 1. Introduction

An encapsulation of the history of the search record function & style Android custom search box

Already open source on Github: address: SearchLayout, welcome Star!

[] ()

[]()2

[]()2.1 Requirement Scenario

[] ()

[]()2.2 Functional requirements

  • Feature list

[] ()

  • The function prototype

[] ()

[]()2.3 Functions

[] ()

[] () 3. Characteristics

[]()3.1 Practical function

  • The open source search box library has not only the function of historical search, but also the general search box functions (such as the key to clear the search box content, etc.).
  • Encapsulates common search box styles (left icon, back button, etc.) and makes it easier to use

[]()3.2 Simple to use

Only simple XML attribute configuration is required

The following section explains how to use it in detail

[]()3.3 Low cost of secondary development

  • This project is already inGithubThe open source:Address: SearchLayout
  • Have a detailed source code analysis document: see article [Android open Source library: Hand teach you to implement a simple and easy to use search box (including historical search records)]

Therefore, it is very cheap to do secondary development & customization on it.

[]()4

This [SearchLayout]() is very easy to use in 2 steps:

[]() Step 1: Import control library

There are two main Gradle and Maven methods:

  • Method 1:GradleIntroduction of depend onbuild.Gradle
Dependencies {compile 'com.carson_ho:SearchLayout:1.0.1'}Copy the code
  • Method 2:MavenIntroduction of depend onpom.xml
< the dependency > < groupId > com. Carson_ho < / groupId > < artifactId > SearchLayout < / artifactId > < version > 1.0.1 < / version > <type>pom</type> </dependency>Copy the code

[]() Step 2: Set the search box style

  • Specific property Settings

[] ()

  • Use examples inXMLFile to setactivity_main.xml
<scut.carson_ho.searchview.SearchView android:id="@+id/search_view" android:layout_width="match_parent" Android :layout_height="wrap_content" app:textSizeSearch=" 5DP "app:textColorSearch="#3F51B5" app:textHintSearch=" Input query keyword"  app:searchBlockHeight="150" app:searchBlockColor="#ffffff" />Copy the code

[]() Step 3: Set the operation after clicking the search button & return button on the keyboard

MainActivity.java

// 1\. Initialize the search box variable private SearchView SearchView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // 2\. Bind view setContentView(r.layout.activity_search); SearchView = (searchView) findViewById(R.i.search_view); / / 4 \. Set the click search button on the keyboard after operation (through callback interface) / / parameter = search box input contents searchView. SetOnClickSearch (new ICallBack () {@ Override public void SearchAciton(String String) {system.out.println (" I received "+ String); SearchAciton(String String) {system.out.println (" I received" + String); }}); / / 5 \. Click the back button set after the operation (through callback interface) searchView. SetOnClickBack (new bCallBack () {@ Override public void BackAciton {() finish (); }}); }}Copy the code

[] (Github.com/Carson-Ho/S…5. Full Demo address

Carson_Ho Github address: SearchLayout

[]