Altering Search Dialog - android

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.

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~

Related

Searchable Activity in Android Studio

I am trying to gather as much information as I can about creating a search interface in Android Studio. I am working with developer.android.com and have a question about using the search interface.
I quote:
<application ... >
<!-- this is the searchable activity; it performs searches -->
<activity android:name=".SearchableActivity" >
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data android:name="android.app.searchable"
android:resource="#xml/searchable"/>
</activity>
<!-- this activity enables the search dialog to initiate searches
in the SearchableActivity -->
<activity android:name=".OtherActivity" ... >
<!-- enable the search dialog to send searches to SearchableActivity -->
<meta-data android:name="android.app.default_searchable"
android:value=".SearchableActivity" />
</activity>
...
"If you want every activity in your application to provide the search dialog, insert the above meta-data element as a child of the application element, instead of each activity. This way, every activity inherits the value, provides the search dialog, and delivers searches to the same searchable activity."
I don't understand the first sentence, unfortunately. What do I have to do exactly in order to have my search dialog in every activity. In this code example, we only have the search dialog in one activity. Can anyone show me using the code above, how to insert meta-data as a child of the application element in my AndroidManifest.xml?
Thank you.
It just describes an easy way of doing things.
You add the <meta-data> element to every activity that you want to have this behaviour of providing a serach dialog. However, if all your activities have this behaviour, instead of adding the <meta-data> element to all of them, you can just add it to the <application> and it'll work as if you added it to all <activity>s. Just add it to your application like:
<application
android:name=".MyApp"
android:icon="#drawable/ic_launcher">
<meta-data android:name="android.app.default_searchable"
android:value=".SearchableActivity" />
...
</application>

Android Global Search

I'm trying to add my app to the global search in Android so users can search my app from their homescreen. I've followed the tutorial at http://developer.android.com/guide/topics/search/search-dialog.html but it won't seem to work. When I test the app and go to the part of the settings where you see all the searchable apps my app doesn't show up. Here's some of my code:
The Mainfest:
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data
android:name="android.app.searchable"
android:resource="#xml/searchable" />
This of course is within the tag.
searchable.xml (res/xml/searchable.xml):
<?xml version="1.0" encoding="utf-8"?>
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
android:includeInGlobalSearch="true"
android:voiceSearchMode="showVoiceSearchButton"
android:label="Holo Wikipedia Search"
android:hint="Search Wikipedia" >
</searchable>
Please leave a commment if there's any more you want to see :)
Did you try using string resources for the label and hint?
Instead of hard-coded strings, try something like this:
android:label="#string/label_string"
android:hint="#string/hint_string"

how to implement search box in my application in android?

i have one activity in my android application in which a list of orders is populated. I want to implement a search functionality on this activity so that user can search for particular order.
I have read about the search box facility provided by adding a searchable.xml file in the application but I am not able to make it work for me?
I just want to add a search box in the activity and search for specific data in database.
How can I do this?
#VNVN I would agree - I would review the developer guide. http://developer.android.com/guide/topics/search/search-dialog.html
You will need to make your activity search-able in the AndroidMainfest.xml file
<activity android:name=".MySearchableActivity" >
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data android:name="android.app.searchable"
android:resource="#xml/searchable"/>
</activity>
You are probably missing creating a SearchableActivity. http://developer.android.com/guide/topics/search/search-dialog.html#SearchableActivity

Search suggestions causing inconsistent behavior in application after triggered from Quick Search Bar

I'm running into an issue with the Quick Search Bar that I'm hoping someone can help me with.
My application includes a Searchable activity used to provide search behavior within my application. That search activity is designed to trigger a separate Intent when the search item is clicked on so as to cause a different Activity to handle the viewing. When used within the application, the search behavior works perfectly every time.
My application also includes a ContentProvider used to provide search suggestions and is also configured to allow use in the Quick Search Bar. When used within the application itself, use of the search suggestions works fine every time it is used. When triggered from the QSB, the initial search suggestion brings up the viewing activity just as it should. After that point, however, any use of the search suggestions from within the application (i.e. bringing up the search and selecting a search suggestion) fails to trigger the viewing application. In fact, I've put debug statements in every single "onXXX()" method within the Searchable activity and I never see any of them get triggered. On the flip side, when I trigger a standard search at that same point (i.e. enter a query string and hit enter, rather than navigating to a search suggestion), the search dialog comes up, as expected, and selecting an item from that list successfully triggers my application.
I'm currently at a loss trying to determine why this would be occurring. Any ideas
As as some additional information, my manifest contains the following in regards to the searchable activity (".activity.SearchableActivity"), the suggestions provider (".content.TestSuggestionProvider") and the activity used to display the content (".activity.TestDisplayActivity"):
<activity
android:name=".activity.TestDisplayActivity"
android:label="#string/app_name"
android:launchMode="singleTask"
android:finishOnTaskLaunch="true"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
android:screenOrientation="landscape"
android:configChanges="orientation|keyboardHidden">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data android:name="android.app.default_searchable" android:value=".activity.SearchableActivity" />
</activity>
<activity
android:name=".activity.SearchableActivity"
android:launchMode="singleTop"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen">
<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>
<provider
android:name=".content.TestSuggestionProvider"
android:authorities="com.test.provider.suggest"
android:syncable="false"
/>
And the following is the XML used to further define the settings of the searchable activity:
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
android:label="#string/search_app_label"
android:hint="#string/search_app_hint"
android:searchSettingsDescription="#string/search_app_settings_description"
android:includeInGlobalSearch="true"
android:voiceSearchMode="showVoiceSearchButton|launchRecognizer"
android:searchSuggestAuthority="com.test.provider.suggest"
android:searchSuggestIntentAction="android.intent.action.VIEW">
</searchable>
Any thoughts? At the moment I'm at a complete loss…

Android: making search available throughout the whole application

Right now I'm adding
<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" />
to every single <activity> in the AndroidManifest.xml, receive the Intent in each activity and forward the search string to one singleTop activity that actually performs the search (via HTTP/JSON) and displays the results in a list.
I'm wondering if there's a way how I can set-up the AndroidManifest.xml, so that search is activated in each activity within my application, but the search string will get forwarded from Android's search box directly to my singleTop SearchResults_Activity instead of going the way through validating events in each activity and then forwarding the search string.
The answer to that is actually available in the SearchManager documentation, in the MetaData chapter.
Activities which are part of a
searchable application, but don't
implement search itself, require a bit
of "glue" in order to cause them to
invoke search using your searchable
activity as their primary context. If
this is not provided, then searches
from these activities will use the
system default search context.
<application>
<meta-data android:name="android.app.default_searchable"
android:value=".MySearchActivity" />
<!-- followed by activities, providers, etc... -->
</application>

Categories

Resources