Android 系统搜索框(有浏览记录)
生活随笔
收集整理的這篇文章主要介紹了
Android 系统搜索框(有浏览记录)
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
實(shí)現(xiàn)Android 系統(tǒng)搜索框(有瀏覽記錄),先看下效果:
一、配置搜索描述文件
要在res中的xml文件加創(chuàng)建sreachable.xml,內(nèi)容如下:
<?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> ??
二、填寫配置文件信息
1.搜索框的配置
<!-- 搜索動(dòng)作 --> ? <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.保存內(nèi)容的配置
<provider ? android:authorities="com.glacier.ui.SearchSuggestionProvider" ? android:name="com.glacier.ui.SearchSuggestionProvider" > ? </provider>?
三、調(diào)用啟動(dòng)搜索框方法
//彈出搜索框 onSearchRequested();
可以重新寫系統(tǒng)的方法做些必要的內(nèi)容加載其他 @Override ? public boolean onSearchRequested(){ ? //打開浮動(dòng)搜索框(第一個(gè)參數(shù)默認(rèn)添加到搜索框的值) ? ? ? ? startSearch(null, false, null, false); ? return true; ? } ? //得到搜索結(jié)果 ? @Override ? public void onNewIntent(Intent intent){ ? super.onNewIntent(intent); ? //獲得搜索框里值 ? query=intent.getStringExtra(SearchManager.QUERY); ? System.out.println(query); ? //保存搜索記錄 ? SearchRecentSuggestions suggestions=new SearchRecentSuggestions(MainActivity.this, ? SearchSuggestionProvider.AUTHORITY, SearchSuggestionProvider.MODE); ? suggestions.saveRecentQuery(query, null); ? System.out.println("保存成功"); ? }?
四、記得要寫存儲(chǔ)的地方
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); ? } ? }?
源碼下載地址
免費(fèi)下載地址在? http://linux.linuxidc.com/
用戶名與密碼都是www.linuxidc.com
具體下載目錄在 /2012年資料/11月/30日/Android 系統(tǒng)搜索框(有瀏覽記錄)
本篇文章來源于 Linux公社網(wǎng)站(www.linuxidc.com) ?原文鏈接: http://www.linuxidc.com/Linux/2012-11/75136.htm
一、配置搜索描述文件
要在res中的xml文件加創(chuàng)建sreachable.xml,內(nèi)容如下:
<?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> ??
二、填寫配置文件信息
1.搜索框的配置
<!-- 搜索動(dòng)作 --> ? <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.保存內(nèi)容的配置
<provider ? android:authorities="com.glacier.ui.SearchSuggestionProvider" ? android:name="com.glacier.ui.SearchSuggestionProvider" > ? </provider>?
三、調(diào)用啟動(dòng)搜索框方法
//彈出搜索框 onSearchRequested();
可以重新寫系統(tǒng)的方法做些必要的內(nèi)容加載其他 @Override ? public boolean onSearchRequested(){ ? //打開浮動(dòng)搜索框(第一個(gè)參數(shù)默認(rèn)添加到搜索框的值) ? ? ? ? startSearch(null, false, null, false); ? return true; ? } ? //得到搜索結(jié)果 ? @Override ? public void onNewIntent(Intent intent){ ? super.onNewIntent(intent); ? //獲得搜索框里值 ? query=intent.getStringExtra(SearchManager.QUERY); ? System.out.println(query); ? //保存搜索記錄 ? SearchRecentSuggestions suggestions=new SearchRecentSuggestions(MainActivity.this, ? SearchSuggestionProvider.AUTHORITY, SearchSuggestionProvider.MODE); ? suggestions.saveRecentQuery(query, null); ? System.out.println("保存成功"); ? }?
四、記得要寫存儲(chǔ)的地方
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); ? } ? }?
源碼下載地址
免費(fèi)下載地址在? http://linux.linuxidc.com/
用戶名與密碼都是www.linuxidc.com
具體下載目錄在 /2012年資料/11月/30日/Android 系統(tǒng)搜索框(有瀏覽記錄)
本篇文章來源于 Linux公社網(wǎng)站(www.linuxidc.com) ?原文鏈接: http://www.linuxidc.com/Linux/2012-11/75136.htm
?
轉(zhuǎn)載于:https://www.cnblogs.com/pangblog/p/3294045.html
總結(jié)
以上是生活随笔為你收集整理的Android 系统搜索框(有浏览记录)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: win7 telnet命令无法使用
- 下一篇: CString的部分实现剖析