I am creating a contacts list view and want to add search view to that activity. I have created a searchable.xml and the contents of which is pasted below
<?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">
</searchable>
I have also added the meta-data tag in the activity as shown here
<activity
android:name=".ContactsWindow"
android:label="@string/title_activity_contacts_window" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data
android:name="android.app.searchable"
android:resource="@xml/searchable">
</meta-data>
</activity>
I have overridden the onCreateOptionsMenu() method
public boolean onCreateOptionsMenu(Menu menu) {
getActionBar().show();
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu_contacts_window, menu);
SearchManager searchManager = (SearchManager)
getSystemService(Context.SEARCH_SERVICE);
searchMenuItem = menu.findItem(R.id.menuSearch);
searchView = (SearchView) searchMenuItem.getActionView();
searchView.setSearchableInfo(searchManager.
getSearchableInfo(getComponentName()));
searchView.setSubmitButtonEnabled(true);
searchView.setOnQueryTextListener(this);
searchView.setIconifiedByDefault(false);
return true;
}
Here is my menu xml for this activity.
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" tools:context="com.gwts.lingua.ContactsWindow">
<item android:id="@+id/menuSearch"
android:title="Search"
android:icon="@drawable/find"
app:showAsAction="ifRoom|collapseActionView"
android:actionViewClass="android.widget.SearchView" />
<item android:id="@+id/action_settings" android:title="@string/action_settings"
android:orderInCategory="100" app:showAsAction="always" />
</menu>
When I install the apk to my phone and try to launch the app, I do not see the searchview on the action bar. What could have possibly gone wrong?