Android Floating Search box

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.