I'm adding voice search capabilities to my app's search interface. Currently, it looks like this:
To add voice search, I added a voiceSearchMode
to my Searchable Configuration, which adds a button in the SearchView to trigger the voice dialog. The interface now looks like this:
However as you can see on the keyboard's ,
key, the microphone button is now disabled. I can't find any documentation on how to turn it on again, and the only related questions explain how to explicitly disable it.
Is it possible to have both the system's voice search dialog and the keyboard's voice input in a SearchView
?
just do your own search view, it is very simple. you then can include this layout in your activity layout file. This is a simple layout which includes a "search icon" followed by EditText, followed by "clear icon". The clear icon is shown after user types some text.
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.
You can use setQuery() to change the text in the textbox. However, setQuery() method triggers the focus state of a search view, so a keyboard will show on the screen after this method has been invoked. To fix this problem, just call searchView.
Invoking the search dialog For instance, you should add a Search button in your Options Menu or UI layout that calls onSearchRequested() . For consistency with the Android system and other apps, you should label your button with the Android Search icon that's available from the Action Bar Icon Pack.
I know this is an old question but couldn't find an answer through Google so thought I'd add here what I found. After taking a look at the SearchView's source code I found the following code in setSearchableInfo
method:
if (mVoiceButtonEnabled) {
// Disable the microphone on the keyboard, as a mic is displayed near the text box
// TODO: use imeOptions to disable voice input when the new API will be available
mSearchSrcTextView.setPrivateImeOptions(IME_OPTION_NO_MICROPHONE);
}
What I then did was to create a class that extends SearchView, override the setSearchableInfo method and after calling super.setSearchableInfo
add the following:
SearchAutoComplete mSearchSrcTextView = findViewById(android.support.v7.appcompat.R.id.search_src_text);
mSearchSrcTextView.setPrivateImeOptions("");
Now I have a microphone on the keyboard and one in the SearchView.
Edit: Don't forget to reference your class if you're using it in the menu.
app:actionViewClass="your.searchview.class"
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