First, configure the search description file
To create the sreachable.xml in the XML file in res, it reads as follows:
<?xml version= "1.0" encoding= "Utf-8"?>
<searchable
Xmlns:android= "Http://schemas.android.com/apk/res/android"
android:hint= "@string/searchlable"
Android:label= "@string/searchlable"
Android:searchsuggestauthority= "Com.glacier.ui.SearchSuggestionProvider"
Android:searchsuggestselection= "? ">
</searchable>
Second, fill in the configuration file information
1. The configuration of the search box
<!--search Action-->
<intent-filter >
<action android:name= "Android.intent.action.SEARCH" >
</action>
</intent-filter>
<meta-data
Android:name= "Android.app.default_searchable"
Android:value= "Mainactivity"/>
<meta-data
Android:name= "Android.app.searchable"
Android:resource= "@xml/searchable" >
</meta-data>
2. Save the Content configuration
<provider
Android:authorities= "Com.glacier.ui.SearchSuggestionProvider"
Android:name= "Com.glacier.ui.SearchSuggestionProvider" >
</provider>
Third, invoke the Start Search box method
Pop-up search box
Onsearchrequested ();
Can write the system method to do the necessary content to load the other
@Override
public Boolean onsearchrequested () {
Open the floating search box (the first parameter is added by default to the value of the search box)
Startsearch (null, FALSE, NULL, FALSE);
return true;
}
Get search Results
@Override
public void Onnewintent (Intent Intent) {
Super.onnewintent (Intent);
Get the value in the search box
Query=intent.getstringextra (Searchmanager.query);
System.out.println (query);
Save a search record
Searchrecentsuggestions suggestions=new searchrecentsuggestions (Mainactivity.this,
Searchsuggestionprovider.authority, Searchsuggestionprovider.mode);
Suggestions.saverecentquery (query, NULL);
System.out.println ("Save Success");
}
Four, remember to write the storage place
import android.content.searchrecentsuggestionsprovider;
public class Searchsuggestionprovider extends Searchrecentsuggestionsprovider {
Public final static String authority= "Com.glacier.ui.SearchSuggestionProvider";
Public final static int mode=database_mode_queries;
Public Searchsuggestionprovider () {
super ();
Setupsuggestions (authority, MODE);
} &NBSP
}