I created a search interface, but I cannot connect SearchView in ActionBar to my searchable configuration file. When I try to find it in my onCreateOptionsMenu SearchManager.getSearchableInfo(getComponentName() method, it returns null. Can someone help me with this?
Settings.onCreateOptionsMenu (menu)
@Override public boolean onCreateOptionsMenu(Menu menu) { super.onCreateOptionsMenu(menu); MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.activity_main, menu); SearchManager sm = (SearchManager) getSystemService(Context.SEARCH_SERVICE); SearchView sv = (SearchView) menu.findItem(R.id.menu_search).getActionView(); SearchableInfo info = sm.getSearchableInfo(getComponentName()); //This variable is returned as null sv.setSearchableInfo(info); sv.setIconifiedByDefault(false); sv.setSubmitButtonEnabled(true); return true; }
Settings in AndroidManifest.xml
<activity android:name=".Settings" android:label="@string/app_name" android:screenOrientation="portrait" > <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" /> </activity>
Search activity in AndroidManifest.xml
<activity android:name=".ImageSearch" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.SEARCH" /> </intent-filter> </activity>
I have the header <?xml version="1.0" encoding="utf-8"?> In my XML menu file and I tried to clear the project. None of them seem to do the trick.
source share