1.创建搜索建议提供者

Android已经为我们创建了一个默认的,我们只需要继承 SearchRecentSuggestionProvider 就稍做修改就可以了。

见代码:

   1: import android.content.SearchRecentSuggestionsProvider;
   2: 
   3: /**
   4:  * 搜索提示
   5:  * 
   6:  * @author Hanguo
   7:  * http://t.sina.com.cn/halzhang
   8:  * @version 2011-1-5上午11:51:39
   9:  */
  10: public class SearchSuggestionsProvider extends SearchRecentSuggestionsProvider {
  11:     //记住这个哦
  12:     public final static String AUTHORITY = "searchprovider";
  13: 
  14:     public final static int MODE = DATABASE_MODE_QUERIES;
  15: 
  16:     public SearchSuggestionsProvider() {
  17:         setupSuggestions(AUTHORITY, MODE);
  18:     }
  19: }

2.配置searchable.xml

   1: <?xml version="1.0" encoding="utf-8"?>
   2: <searchable xmlns:android="http://schemas.android.com/apk/res/android"
   3:     android:label="@string/search_label" 
   4:     android:hint="@string/search_hint"
   5:     android:searchSettingsDescription="@string/search_settings_description"
   6:     android:searchSuggestAuthority="searchprovider"
   7:     android:searchSuggestIntentAction="android.intent.action.SEARCH"
   8:     android:searchSuggestThreshold="1"
   9:     android:includeInGlobalSearch="true"
  10:     android:searchSuggestSelection=" ?"
  11:     >
  12: </searchable>
参数说明: android:searchSuggestAuthorith 此属性的值就是SearchSuggestAuthorith中的AUTHORITH了。 android:searchSuggestIntentAction 此属性定义了当我们选中搜索提示的内容时发生的目的动作。 android:searchSuggestThreshold 此属性定义了至少输入几个字符时才会弹出提示 android:includeInGlobalSearch 是否将内容加入android的全局搜索。true,加入。 android:searchSuggestSelection 定义搜索时参数的占位符

更多相关文章

  1. Android(安卓)Studio & ADT 快捷键配置文件所在目录,自定义后可导
  2. Android架构分析之使用自定义硬件抽象层(HAL)模块
  3. android 自定义view
  4. [Android] ACTION_GET_CONTENT与ACTION_PICK的区别
  5. Android(安卓)UI系列 - 布局 - 目录
  6. android Manifest.xml选项-android:ConfigChanges
  7. linearLayout 和 relativeLayout的属性区别
  8. android listview custom style 自定义样式
  9. android实践项目一实现简单的验证码和spinner下拉选项效果

随机推荐

  1. Android插件配置-Android Extension介绍
  2. android 重力感应初步认识
  3. Android调用输入法软键盘,返回输入的内容
  4. android中使用afinal一行代码显示网络图
  5. Android文件系统保护——dmverity
  6. Camera Flash的获得权限
  7. 2.5.3 使用alertDialog创建自定义对话框
  8. Android 已发行多年,移动 App 已经趋近饱
  9. Fetching https://dl-ssl.google.com/and
  10. 登录案例_android