I have a seachview in layout file named activity_products_final
<android.support.v7.widget.SearchView
android:id="@+id/searchView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:queryHint="Search..">
</android.support.v7.widget.SearchView>
</LinearLayout>
Activity:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_products_final);
searchView = (android.support.v7.widget.SearchView) findViewById(R.id.searchView);
searchView.setIconified(false);
searchView.onActionViewExpanded();
searchView.clearFocus();
searchView.setOnQueryTextListener(new android.support.v7.widget.SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
if (adapter != null)
filterData(query);
return false;
}
@Override
public boolean onQueryTextChange(String query) {
if (adapter != null)
filterData(query);
return false;
}
});
ImageView closeButton = (ImageView) searchView.findViewById(R.id.search_close_btn);
closeButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
searchView.setQuery("", false);
searchView.clearFocus();
//collapseAll();
}
});
}
manifest file
<activity
android:name=".ActivityProductList"
android:configChanges="orientation|screenSize"
android:label="@string/title_activity_products"
android:launchMode="singleTop"
android:parentActivityName=".ActivityStartShopping"
android:screenOrientation="portrait"
>
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data
android:name="android.app.searchable"
android:resource="@xml/searchable" />
</activity>
xml/searchable
<?xml version="1.0" encoding="utf-8"?>
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
android:label="@string/app_name"
android:hint="@string/search_hint"
android:voiceSearchMode="showVoiceSearchButton|launchRecognizer"
>
</searchable>
As per google docs i have to use android:voiceSearchMode="showVoiceSearchButton|launchRecognizer" to show MIC button.
I followed the doc but it is not showing MIC button to capture voice input.
Can anyone help me on this?
You need to create a SearchableConfiguration. Add this as searchable.xml
in your xml resource folder:
<?xml version="1.0" encoding="utf-8"?>
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
android:hint="search..."
android:label="@string/app_name"
<!-- the next line enables the voice button display -->
android:voiceSearchMode="showVoiceSearchButton|launchRecognizer"/>
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