I would like to know if it is possible to set voice listener on my searchView, like the suggestion listener: http://developer.android.com/reference/android/support/v7/widget/SearchView.OnSuggestionListener.html
I want to overwrite the default behavior. I don't want to launch another activity. I just want to get the recorded voice as a string and use it.
SearchView widget can be implemented over ToolBar/ActionBar or inside a layout. SearchView is by default collapsible and set to be iconified using setIconifiedByDefault(true) method of SearchView class. For making search field visible, SearchView uses setIconifiedByDefault(false) method.
public abstract boolean onQueryTextSubmit (String query) Called when the user submits the query. This could be due to a key press on the keyboard or due to pressing a submit button. The listener can override the standard behavior by returning true to indicate that it has handled the submit request.
Add the Search View to the App Bar To add a SearchView widget to the app bar, create a file named res/menu/options_menu. xml in your project and add the following code to the file. This code defines how to create the search item, such as the icon to use and the title of the item.
I read what you ask for, but Why don't you want to use an activity? Just in case this can help you, you should take a look at these if you havn't till now:
Andriod developers: http://developer.android.com/guide/topics/search/search-dialog.html#VoiceSearch
Examples:
http://www.codeproject.com/Articles/821839/A-Beginners-Guide-to-Working-With-Speech-and-Audio http://www.truiton.com/2014/06/android-speech-recognition-without-dialog-custom-activity/
Hope it helps, yakobom
To show the microphone icon you need to add a search configuration and set it to your SearchView. See this question and my answer here https://stackoverflow.com/a/48527608/114549
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With