Display SearchView in ActionBar Android -


i trying display searchview inside actionbar of activity. followed android developer guide here here no searchview displayed , cannot figure out why. here there code of activity

    public class searchactivity extends actionbaractivity {       private string query;      @override     protected void oncreate(bundle savedinstancestate) {          facebooksdk.sdkinitialize(getapplicationcontext());         super.oncreate(savedinstancestate);         setcontentview(r.layout.search_activity_layout);           intent intent = getintent();         if (intent.action_search.equals(intent.getaction())) {             this.query = intent.getstringextra(searchmanager.query);             toast.maketext(this,query, toast.length_long);         }      }      @override     public boolean oncreateoptionsmenu(menu menu) {          menuinflater inflater = getmenuinflater();         inflater.inflate(r.menu.options_menu, menu);          return true;     }  } 

here serachable.xml file

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

here there options_menu.xml file

<?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android">     <item android:id="@+id/search"         android:title="@string/search_title"         android:icon="@drawable/ic_action_search"         android:showasaction="collapseactionview|ifroom"         android:actionviewclass="android.widget.searchview" /> </menu> 

and manifest

<activity android:name=".searchactivity"               android:label="searchactivity">          <intent-filter>             <action android:name="android.intent.action.search" />         </intent-filter>         <meta-data android:name="android.app.searchable"             android:resource="@xml/searchable"/>       </activity> 

the strange thing line (android:showasaction="collapseactionview|ifroom") in options_menu.xml file highlighted in red.

try putting in options_menu.xml:

<?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:app="http://schemas.android.com/apk/res-auto">      <item android:id="@+id/search"         android:title="@string/search_title"         android:icon="@drawable/ic_action_search"         app:actionviewclass="android.widget.searchview"         app:showasaction="collapseactionview|ifroom" /> </menu> 

and in androidmanifest.xml

<activity android:name=".searchactivity"     android:label="searchactivity">      <intent-filter>         <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=".searchactivity" /> </activity> 

and in searchactivity.java

@override public boolean oncreateoptionsmenu(menu menu) {     menuinflater inflater = getmenuinflater();     inflater.inflate(r.menu.options_menu, menu);      searchmanager searchmanager = (searchmanager) getsystemservice(context.search_service);     searchview searchview = (searchview) menu.finditem(r.id.search).getactionview();     searchview.setsearchableinfo(searchmanager.getsearchableinfo(getcomponentname()));     searchview.seticonifiedbydefault(false);      return true; }  @override protected void onnewintent(intent intent) {     setintent(intent);      if (intent.action_search.equals(intent.getaction())) {         log.e("query", intent.getstringextra(searchmanager.query));     } } 

Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -