android 系统搜索框(有浏览记录)
来源:互联网 发布:软件系统开发合同 编辑:程序博客网 时间:2024/05/21 01:48
先看下效果:
一、配置搜索描述文件
要在res中的xml文件加创建sreachable.xml,内容如下:
<?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.搜索框的配置
<!-- 搜索动作 --> <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.保存内容的配置
<provider android:authorities="com.glacier.ui.SearchSuggestionProvider" android:name="com.glacier.ui.SearchSuggestionProvider" > </provider>
三、调用启动搜索框方法
//弹出搜索框
onSearchRequested();
可以重新写系统的方法做些必要的内容加载其他
@Overridepublic boolean onSearchRequested(){//打开浮动搜索框(第一个参数默认添加到搜索框的值) startSearch(null, false, null, false);return true;} //得到搜索结果 @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("保存成功"); }
四、记得要写存储的地方
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);}}
欢迎各位开发人员探讨知识!!!
源码下载地址http://download.csdn.net/detail/wang_yubin/4472156
- android 系统搜索框(有浏览记录)
- Android 系统搜索框(有浏览记录)
- Android 系统搜索框(有浏览记录)
- android 浏览器浏览记录
- Android搜索框存储搜索记录
- Android 保存浏览记录 SharedPreTools
- Android系统搜索对话框(浮动搜索框)的使用
- Android系统搜索对话框(浮动搜索框)的使用
- Android系统搜索对话框(浮动搜索框)的使用
- Android系统搜索对话框(浮动搜索框)的使用
- Android系统搜索对话框(浮动搜索框)的使用
- Android系统搜索对话框(浮动搜索框)的使用
- Android系统搜索对话框(浮动搜索框)的使用
- Android系统搜索对话框(浮动搜索框)的使用
- 实现搜索的历史浏览记录,含数据库
- android 浏览器搜索记录
- Android常用:手把手教你实现搜索框(含历史搜索记录)
- Android常用:手把手教你实现搜索框(含历史搜索记录)
- POJ 2689 Prime Distance (经典素数筛选)
- 多线程并发处理
- PKU 3468 A Simple Problem with Integers
- 现实世界的Windows Azure:与iQmetrix的市场营销副总裁Anne Weiler对话
- f16
- android 系统搜索框(有浏览记录)
- 多线程
- Javascript代码优化
- f17
- 如何修改本机的MTU
- f18
- 设计模式之--动态代理
- android I/DEBUG堆栈信息
- 硬盘引导安装ubuntu12.04