The configuration of the Android floating search box is cumbersome and requires a good XML file to be configured to implement the Onsearchrequest () method.
1. Configure the search XML configuration file?, create a new file Searchable.xml, and save it in the Res/xml folder.
1 <?XML version= "1.0" encoding= "UTF-8"?>2 3 <searchableAndroid:label= "@string/search_label"4 android:searchsuggestauthority= "Search"5 android:searchsuggestintentaction= "Android.intent.action.VIEW"6 xmlns:android= "Http://schemas.android.com/apk/res/android"7 />
2. Create a new Searchactivity.java, inherit activity, in configuration file manifest.xml? Add the following information
1 <Activity2 Android:name=". Searchactivity "3 Android:launchmode= "Singletop" 4 Android:label= "@string/app_name" >5 6 <Intent-filter> 7 <ActionAndroid:name= "Android.intent.action.SEARCH" /> 8 <categoryAndroid:name= "Android.intent.category.DEFAULT" /> 9 </Intent-filter> Ten <!--Specify the Searchable.xml file above - One <Meta-dataAndroid:name= "Android.app.searchable" A Android:resource= "@xml/searchable" /> - </Activity>
3. At this point, the Onsearchrequest method can be used, this method will bring up the Android floating search box?, the Java code is as follows
1 Public classSearchactivityextendsActivity {2 ?3 Public voidonCreate (Bundle savedinstancestate) {4 Super. OnCreate (savedinstancestate);5 6Intent Intent = This. Getintent ();7 8 if(Intent.ACTION_SEARCH.equals (Intent.getaction ())) {9String query =Intent.getstringextra (searchmanager.query); Ten dosearch (query); One } A Else{ - onsearchrequested (); - the } - - } - + Private voidDosearch (String querystr) { - //perform true query result processing + } A at}
Android Floating Search box