android - SearchView getActionView returning null -


this working few days ago, stopped. want use action bar search widget when fragment visible.

now i'm unable searchview, getactionview returns null.

searchable.xml

<?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_for_places"> </searchable> 

manifest.xml

<activity     android:name=".ui.activities.mainactivity"     android:launchmode="singletop">     <intent-filter>         <action android:name="android.intent.action.main"/>         <category android:name="android.intent.category.launcher"/>         <action android:name="android.intent.action.search"/>     </intent-filter>     <meta-data         android:name="android.app.searchable"         android:resource="@xml/searchable"/>     <meta-data     android:name="android.app.default_searchable"     android:value=".ui.activities.mainactivity" /> </activity> 

menu.xml

<menu xmlns:android="http://schemas.android.com/apk/res/android"   xmlns:myapp="http://schemas.android.com/apk/res-auto">     <item         android:id="@+id/action_search_place"         android:icon="@drawable/ic_2_action_search"         android:orderincategory="1"         android:title="@string/title_search"         myapp:showasaction="collapseactionview|ifroom"         myapp:actionviewclass="android.support.v7.widget.searchview"/> </menu> 

the fragment

... sethasoptionsmenu(true); ...    @override public void oncreateoptionsmenu(final menu menu, final menuinflater inflater) {     inflater.inflate(r.menu.menu, menu);     menuitem searchitem = menu.finditem(r.id.action_search_place);     msearchview = (searchview) menuitemcompat.getactionview(searchitem);      searchmanager searchmanager = (searchmanager) getbaseactivity().getsystemservice(context.search_service);     if (msearchview != null) {         msearchview.setsearchableinfo(searchmanager.getsearchableinfo(getactivity().getcomponentname()));         msearchview.seticonifiedbydefault(true);         msearchview.setonquerytextlistener(this);     }     super.oncreateoptionsmenu(menu, inflater); } 

today had same problem , think solved it. turns out did couple of things not per actionbarcompat contract:

  • each activity uses actionbarcompat should extend actionbaractivity instead of fragmentactivity directly
  • each activity uses actionbarcompat should declare theme inheriting actionbarcompat themes.

both of found watching explanation video google.

now searchview not null anymore.


Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -