2011-05-27 189 views
6

是否可以在我的活動中更改搜索對話框(Android 3.0之前)?這是您按下硬件搜索按鈕時會下降的搜索欄。通過改變,我的意思是修改佈局。如果可以的話,我想添加一個額外的按鈕。更改搜索對話框

+1

問題[這裏](http://stackoverflow.com/questions/4150904/android-custom-quick-搜索框)看起來像你所需要的。看來,要走的路是在您的活動中攔截「onSearchRequested」並創建自己的界面。 – Craigy 2011-10-23 20:57:44

+0

你可以輕鬆地做到這一點。請參閱此處的答案:http://stackoverflow.com/a/44131089/3649347 – GeekOnJava 2017-05-23 10:14:49

回答

1

我認爲,浮動搜索框是你想要什麼〜 它並不難,但它的配置稍微複雜〜 首先,你需要配置的搜索欄的參數 新一searchable.xml輪廓是這樣的:

<searchable xmlns:android=http://schemas.android.com/apk/res/android 

  <!-- label is the text at the bottom of the search bar,hint is the text in the search bar --> 
    android:label="@string/search_label" 
    android:hint="@string/search_hint" 
    android:searchMode="showSearchLabelAsBadge" 

  <!-- voice search --> 
    android:voiceSearchMode="showVoiceSearchButton|launchRecognizer" 
    android:voiceLanguageModel="free_form" 
    android:voicePromptText="@string/search_invoke" 


    <!-- Configure search suggestions--> 

   android:searchSuggestAuthority="com.android.cbin.SearchSuggestionSampleProvider" 
    android:searchSuggestSelection=" ? " 
/> 

你應該在mainfest.xml做到這一點:

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

      
<!-- searchable.xml --> 

<meta-data android:resource="@xml/searchable" 

   android:name="android.app.searchable"></meta-data> 

</activity> 
<!-- For each Activity can use search bar, 
be sure to start the label into the Activity 
in which the value is the search results--> 
<meta-data android:name="android.app.default_searchable" 
    android:value=".SearchResultActivity" 
/> 

<provider android:name="SearchSuggestionSampleProvider" 

android:authorities="com.android.cbin.SearchSuggestionSampleProvider"></provider> 

然後覆蓋活動

的onSearchRequested功能

差不多是這樣,忘了細節〜。〜!!!

好運〜