首页 > 移动平台 > 详细

android浮动搜索框

时间:2015-03-13 20:34:09      阅读:387      评论:0      收藏:0      [点我收藏+]

android浮动搜索框的配置比较繁琐,需要配置好xml文件才能实现onSearchRequest()方法。

1.配置搜索的XML配置文件?,新建文件searchable.xml,保存在res/xml文件夹中。

1 <?xml version="1.0" encoding="UTF-8"?>
2 
3 <searchable android:label="@string/search_label"
4     android:searchSuggestAuthority="search"
5   android:searchSuggestIntentAction="android.intent.action.VIEW"
6      xmlns:android="http://schemas.android.com/apk/res/android"
7      />

 

2.新建一个SearchActivity.java,继承Activity,在配置文件manifest.xml中?添加如下信息

 1     <activity
 2             android:name=".SearchActivity"
 3             android:launchMode="singleTop" 
 4             android:label="@string/app_name" >
 5             
 6             <intent-filter>  
 7                 <action android:name="android.intent.action.SEARCH" />   
 8                 <category android:name="android.intent.category.DEFAULT" />   
 9             </intent-filter>  
10             <!-- 指定上面的searchable.xml文件 -->  
11             <meta-data android:name="android.app.searchable" 
12                         android:resource="@xml/searchable" />
13         </activity>

3.至此,onSearchRequest方法才可以使用,该方法会调出android的浮动搜索框?,java代码如下

 1 public class SearchActivity extends Activity { 
 2 ?
 3     public void onCreate(Bundle savedInstanceState) { 
 4         super.onCreate(savedInstanceState); 
 5 
 6         Intent intent = this.getIntent();
 7 
 8         if(Intent.ACTION_SEARCH.equals(intent.getAction())) {  
 9             String query =  intent.getStringExtra(SearchManager.QUERY);  
10             doSearch(query);  
11         } 
12         else{
13             onSearchRequested();
14 
15         }
16 
17     }
18 
19     private void doSearch(String queryStr) {  
20         //执行真正的查询结果处理 
21     } 
22 
23 }        

 

android浮动搜索框

原文:http://www.cnblogs.com/pngcui/p/4335844.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!