Android system has a browser record search box

Source: Internet
Author: User

1. Configure the search description file

Add sreachable. xml to the xml file in res. The content is 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>

2. Fill in the configuration file information

1. Search box Configuration

<! -- 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 content Configuration

<Provider
Android: authorities = "com. glacier. ui. SearchSuggestionProvider"
Android: name = "com. glacier. ui. SearchSuggestionProvider">
</Provider>

3. Call the method for starting the search box

// The search box is displayed.
OnSearchRequested ();

You can re-write the system method and load other necessary content.
@ Override
Public boolean onSearchRequested (){
// Open the floating search box (the value of the first parameter added to the search box by default)
StartSearch (null, false, null, false );
Return true;
}

// Obtain the search result
@ Override
Public void onNewIntent (Intent intent ){
Super. onNewIntent (intent );
// Obtain the value in the search box
Query = intent. getStringExtra (SearchManager. QUERY );
System. out. println (query );
// Save search records
SearchRecentSuggestions suggestions = new SearchRecentSuggestions (MainActivity. this,
SearchSuggestionProvider. AUTHORITY, SearchSuggestionProvider. MODE );
Suggestions. saveRecentQuery (query, null );
System. out. println ("saved successfully ");
}

4. Remember where to write Storage

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 );
}
}

Related Article

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.