How to add mic button in searchview of actionbar - android

I want to add mic in searchview of actionbar.
I tried this ActionBar Mic Button(Voice Search) in SearchView. but mic is not showing in searchview
Please help

here is the link to add voice Search. here

Add this lines in your searchable.
android:voiceSearchMode="showVoiceSearchButton|launchRecognizer"
and put the android:launchMode="singleTop" in your Manifest's activity tag.
<activity android:name=".Activity.MainActivity"
android:launchMode="singleTop"
>
....
<intent-filter>
<action android:name="android.intent.action.SEARCH"></action>
</intent-filter>
<meta-data android:name="android.app.default_searchable"
android:value=".Activity.MainActivity"
></meta-data>
<meta-data android:name="android.app.searchable"
android:resource="#xml/searchable">
</meta-data>
</activity>

Related

android up button is not working as expected

I'm followed https://developer.android.com/training/appbar/up-action.html to add an up button for the app bar.
my manifest is
<activity
android:name=".activity.MyDiaryAct"
android:label="#string/title_activity_my_diary"
android:theme="#style/Theme.AppCompat.Light.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".activity.PageListAct"
android:label="#string/title_page_list"
android:theme="#style/AppTheme.NoActionBar"
android:parentActivityName=".activity.MyDiaryAct">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="activity.MyDiaryAct" />
</activity>
<activity
android:name=".activity.PageAct"
android:label="#string/title_page_name"
android:screenOrientation="portrait"
android:theme="#style/AppTheme.NoActionBar"
android:parentActivityName=".activity.PageListAct" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="activity.PageListAct" />
</activity>
I started PageAct from MyDiaryAct and click up button. It returned to myDiaryAct but I'm expecting PageListAct.
My codes at PageAct
android.support.v7.app.ActionBar ab = getSupportActionBar();
ab.setTitle(page.getName());
ab.setDisplayHomeAsUpEnabled(true);
What am I missing? I wish not to add codes at onOptionsItemSelected(). Thanks!
PS: I'm using targetSdkVersion 23.
UPDATE: while the possible duplicate post provides useful information and direction to solve my problem but the complete understanding and solution found at here.
https://developer.android.com/training/implementing-navigation/ancestral.html
In short, the parent has to be in backs tack else I need to create it manually.

Android Search Activity and android:launchMode="singleTop"

I have a single activity in my app that uses a SearchView to search (see manifest-- the search intent is intercepted).
However, when I press search, nothing happens. The activity never re-starts itself. So, I removed android:launchMode="singleTop" from my activity and then it started re-starting itself and "working." However, it is preferable to have singleTop for me so that the activity only has one instance. Why is this not working when I have singleTop?
<activity
android:name="com.brianco.andypedia.MainActivity"
android:label="#string/app_name"
android:launchMode="singleTop" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data android:name="android.app.searchable" android:resource="#xml/searchable" />
</activity>
<meta-data android:name="android.app.default_searchable"
android:value=".MainActivity" />
I don't know if this answers your question, but this page shows a simple searchview example with ActionBar Compat (it is the new google library compatible for the old Android versions)
You need to process your search intent on onNewIntent besides onCreate.

Android Searchable Configuration not getting attached to SearchView

I'm currently working on adding search ability to my app but I'm facing some problems. First of all I'd just like to clear out that I don't want to create a search activity, I just want to use the Action Bar SearchView and press on suggestions to perform the search.
I've created a SearchView which expands correctly although it doesn't seem like it can attach to my Searchable Configuration xml object. I added this line of code:
android:voiceSearchMode="showVoiceSearchButton|launchRecognizer"
Yet my SearchView doesn't seem to be affected by it. The same goes for this line of code:
android:hint="Search my stuff"
Again, no effect.
Here's my activity in my AndroidManifest.xml:
<activity
android:name="com.simon.holocountownapp.ItemListActivity"
android:label="Holo Countdown" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data
android:name="android.app.searchable"
android:resource="#xml/searchable" />
</activity>
Here's my setup of the SearchView in my onCreateOptionsMenu():
searchView = (SearchView) menu.findItem(R.id.abSearch)
.getActionView();
SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
searchView.setSearchableInfo(searchManager
.getSearchableInfo(getComponentName()));
searchView.setIconifiedByDefault(false);
searchView.setQueryRefinementEnabled(true);
So to summarise things:
The tags used to my searchable.xml doesn't seem to attach to my SearchView, what am I doing wrong?
Thanks for taking the time to read this, I hope you can help me :)
You need to add the android.intent.action.SEARCH intent filter as well. See the code here for reference.
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
I think you also need a <meta-data> element as a child of the <application> element
<application>
<meta-data
android:name="android.app.default_searchable"
android:value="com.simon.holocountownapp.ItemListActivity" >
</meta-data>
</application>
I don't recall if this is documented. I think I found it in one of the sample applications.
I had the same problem, seems that I was missing the default searchable meta-data tag in the manifest.
Add this where you declare the Activity that sends the search to the searchable Activity:
<meta-data android:name="android.app.default_searchable"
android:value=".SearchableActivity" />
Your manifest should look like this:
<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>
...
docs

How to add quick search box to our application?

How to add quick search box (QSB) to our application?
Check this page on more info about the QSB in android.
and add this to your activity in the manifest
<activity android:name=".MyActivity" >
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data android:name="android.app.searchable"
android:resource="#xml/searchable"/>
</activity>

How to declare 2 search activities in android manifest

I am trying to implement two different searchable activities, one for honeycomb(with search widget) and others for non-honeycomb(with search dialog).
My Manifest looks like:
<activity android:name=".activities.Search"
android:theme="#style/NoTitleTheme"
android:configChanges="orientation|keyboardHidden"
android:launchMode="singleTop">
android:enabled="#bool/disableForNonHoneycomb"
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data android:name="android.app.searchable"
android:resource="#xml/searchable"
android:value=".activities.Search"/>
</activity>
<activity android:name=".activities.SearchHoneycomb"
android:theme="#style/CustomTheme"
android:configChanges="orientation|keyboardHidden"
android:enabled="#bool/enableForNonHoneycomb"
android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data android:name="android.app.searchable"
android:resource="#xml/searchable"
android:value=".activities.SearchHoneycomb"/>
</activity>
And, I use following code to get the searchable configuration and set up the search view in my activity.
SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
_searchView = (SearchView) mCustomView.findViewById(R.id.action_bar_searchwidget);
_searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
Problem is that when I use the search widget, it does not start the SearchHoneycomb activity. How can I make this work?
Thanks.
So, after a lot of investigation... there is no way to have 2 searchable activities as android manifest only accepts 1 meta-data for default-searchable.
I got a work around by using a search dialog with default-searchable meta-data and the implemented the querytextlistener for search widget.

Categories

Resources