I have a seachview file in a layout file called 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();
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 / search
<?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>
According to google docs, I have to use android: voiceSearchMode = "showVoiceSearchButton | launchRecognizer" to show the MIC button.
I followed the document, but it does not show the MIC button for recording voice input.
Can someone help me with this?
source share