Android SearchView 鍩烘湰浣跨敤

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Android SearchView 鍩烘湰浣跨敤相关的知识,希望对你有一定的参考价值。

鏍囩锛?/p>

1.鍦╮es/menu/鏂囦欢澶逛笅寤虹珛menu.xml 閰嶇疆鏂囦欢

<menu
  xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@+id/search" android:title="@string/search" 
    android:icon="@drawable/search_app_icon" 
    android:showAsAction="ifRoom|withText" //鍦╝ctionBar鏄剧ず锛?br />    android:actionViewClass="android.widget.SearchView"
    
    ></item>

</menu>

2.鏂板缓涓€涓猘ctivity锛屽苟涓鸿activity娣诲姞鑿滃崟椤?CreateOptionSMenu浠g爜

 @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // TODO Auto-generated method stub
       mi.inflate(R.menu.my_menu, menu);
        MenuItem search=menu.findItem(R.id.search);
         search.collapseActionView();
         SearchView searchview=(SearchView) search.getActionView();
        searchview.setIconifiedByDefault(false);
         SearchManager mSearchManager=(SearchManager)getSystemService(Context.SEARCH_SERVICE);
             SearchableInfo info=mSearchManager.getSearchableInfo(getComponentName());
               searchview.setSearchableInfo(info); //闇€瑕佸湪Xml鏂囦欢鍔犱笅寤虹珛searchable.xml,鎼滅储妗嗛厤缃枃浠?br />           return true;
    }
3.鍦▁ml鏂囦欢澶逛笅绠€鍘唖earchable.xml

  <searchable xmlns:android="http://schemas.android.com/apk/res/android"
        android:label="@string/app_name"
        android:hint="@string/search_title"
      
        android:searchSettingsDescription="@string/search_title"
        android:searchSuggestAuthority="com.digua.fncontact.familyName"
        android:searchSuggestIntentAction="android.intent.action.VIEW"
        android:searchSuggestIntentData="content://com.digua.fncontact.familyName/fname"
        android:searchSuggestSelection=" ?"
        android:searchSuggestThreshold="1"
        android:inputType="text"  
       android:voiceSearchMode="showVoiceSearchButton|launchRecognizer"
       android:searchMode="queryRewriteFromText"
        android:includeInGlobalSearch="true"
        android:queryAfterZeroResults="true"
        >
 </searchable>

 

鍘熸枃鍦板潃锛歨ttp://blog.csdn.net/suichukexun/article/details/7592113

以上是关于Android SearchView 鍩烘湰浣跨敤的主要内容,如果未能解决你的问题,请参考以下文章

銆愰┍鍔ㄣ€戣Е鎽稿睆TP

PHP鍩烘湰璇硶

python鍩烘湰璇硶(鎸佺画鏇存柊)

鍩烘湰妯$増

redis鍩烘湰鎿嶄綔

redis 鍩烘湰鍛戒护