ApiDemo学习 search 组件

   <activity
            android:name=".app.SearchInvoke"
            android:label="@string/search_invoke" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.SAMPLE_CODE" />
            </intent-filter>

           
            <!-- 点击候选结果后跳转到哪里 -->
            <meta-data
                android:name="android.app.default_searchable"
                android:value=".app.SearchQueryResults" />
        </activity>

SearchInvoke java代码 主要方法

   @Override
    public boolean onSearchRequested() {
      
    
        final String queryPrefill = mQueryPrefill.getText().toString();//关键字搜索
        
     
        Bundle appDataBundle = null;
        final String queryAppDataString = mQueryAppData.getText().toString();
        if (queryAppDataString != null) {
            appDataBundle = new Bundle();
            appDataBundle.putString("demo_key", queryAppDataString);//设置开启search activity app的信息
        }
        
        // Now call the Activity member function that invokes the Search Manager UI.
        startSearch(queryPrefill, false, appDataBundle, false); 
        
        // Returning true indicates that we did launch the search, instead of blocking it.
        return true;
    }
搜索结果后的处理
 <activity
            android:name=".app.SearchQueryResults"
            android:label="@string/search_query_results" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.SAMPLE_CODE" />
            </intent-filter>

           

            <intent-filter>
                <action android:name="android.intent.action.SEARCH" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>

          

            <meta-data
                android:name="android.app.searchable"
                android:resource="@xml/searchable" />
        </activity>

 /**
     * Generic search handler.
     * 
     * In a "real" application, you would use the query string to select results from
     * your data source, and present a list of those results to the user.
     */
    private void doSearchQuery(final Intent queryIntent, final String entryPoint) {
        
        // The search query is provided as an "extra" string in the query intent
        final String queryString = queryIntent.getStringExtra(SearchManager.QUERY);
        mQueryText.setText(queryString);
        
        // Record the query string in the recent queries suggestions provider.
        SearchRecentSuggestions suggestions = new SearchRecentSuggestions(this, 
                SearchSuggestionSampleProvider.AUTHORITY, SearchSuggestionSampleProvider.MODE);
        suggestions.saveRecentQuery(queryString, null);
        
   
        final Bundle appData = queryIntent.getBundleExtra(SearchManager.APP_DATA);
        if (appData == null) {
            mAppDataText.setText("<no app data bundle>");
        }
        if (appData != null) {
            String testStr = appData.getString("demo_key");//前面设置的key
            mAppDataText.setText((testStr == null) ? "<no app data>" : testStr);
        }
        
        // Report the method by which we were called.
        mDeliveredByText.setText(entryPoint);
    }
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
    android:label="@string/search_label"
    android:hint="@string/search_hint"//hint时候的文字
    
    android:voiceSearchMode="showVoiceSearchButton|launchRecognizer"
    android:voiceLanguageModel="free_form"
    android:voicePromptText="@string/search_invoke"

    android:searchSuggestAuthority="com.example.android.apis.SuggestionProvider"
    android:searchSuggestSelection=" ? "
/>


更多 参考资料

http://mobile.51cto.com/abased-350777.htm

http://shockwave.iteye.com/blog/737528

 在快速搜索框中显示搜索结果

如何在Android Quick Search Box中添加自己的app,按照我的意愿去Search。


http://blog.youkuaiyun.com/yiyaaixuexi/article/details/6218823

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值