手机
当前位置:查字典教程网 >编程开发 >安卓软件开发 >Android 系统有浏览记录搜索框
Android 系统有浏览记录搜索框
摘要:一、配置搜索描述文件要在res中的xml文件加创建sreachable.xml,内容如下:二、填写配置文件信息1.搜索框的配置2.保存内容的...

一、配置搜索描述文件

要在res中的xml文件加创建sreachable.xml,内容如下:

<?xml version="1.0" encoding="utf-8"?>
<searchable
xmlns:android="/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();

可以重新写系统的方法做些必要的内容加载其他
@Override
public 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);
}
}

【Android 系统有浏览记录搜索框】相关文章:

查看Android应用所需权限

Android监听文件和目录动态

Android 解析JSON对象及实例说明

关于Android SDCard存储的问题

Android手机保持屏幕高亮方法

Android控件系列之CheckBox使用介绍

android上的一个网络接口和图片缓存框架enif简析

Android相册效果

Android开发之WebView组件的使用解析

Android 自定义View的使用介绍

精品推荐
分类导航