6

Is it possible to alter the Search Dialog (prior to Android 3.0) on my Activity? This is the search bar that drops down when you press the hardware search button. By alter, I mean modify the layout. I'd like to add an additional button to it if I could.

Andrew
  • 20,756
  • 32
  • 99
  • 177
  • 1
    The question [here](http://stackoverflow.com/questions/4150904/android-custom-quick-search-box) looks like what you need. It seems that the way to go is to intercept `onSearchRequested` in your activity and create your own interface. – skynet Oct 23 '11 at 20:57
  • You can do it easily. see the answer here : http://stackoverflow.com/a/44131089/3649347 – Tell Me How May 23 '17 at 10:14

1 Answers1

1

I think floating search box is what you want ~ It's not difficult but its configuration is a little more complicated~ First you need configure parameter of the search bar new a searchable.xml profile like this:

<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=" ? "
/>

you should do this in the 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>

then override the onSearchRequested function of Activity

almost like this ,forget the details ~。~!!!

Good luck~

MoiTempete
  • 32
  • 5