android - How to make SearchView behave in a standard way? -


when adding searchview menu (see example below), it's icon doesn't change , behaves in non-standard way. example, long clicking on search menu button should have popped text search, doesn't.

how change behavior more standard? (icon , long click now. i'm sure there other issues)

code sample adding view:

menuitem item = menu.add("search"); searchview sv = new searchview(getactivity()); item.setactionview(sv); item.seticon(drawable.menu_search); item.setshowasaction(menuitem.show_as_action_if_room); 

thanks.

update: possible code. have add menuitem.show_as_action_collapse_action_view , change context of searchview getactionbar().getthemedcontext().

menuitem item = menu.add("search"); searchview sv = new searchview(getactionbar().getthemedcontext()); item.setactionview(sv); item.seticon(r.drawable.ic_search); item.setshowasaction(menuitem.show_as_action_collapse_action_view         | menuitem.show_as_action_if_room); 

you trying create searchview action item code not suggested way it. define menu resource containing search item this:

<menu xmlns:android="http://schemas.android.com/apk/res/android" >      <item         android:id="@+id/search"         android:actionviewclass="android.widget.searchview"         android:icon="@drawable/ic_search"         android:showasaction="collapseactionview|ifroom"         android:title="@string/search_title"/>  </menu> 

inflate in oncreateoptionsmenu:

public boolean oncreateoptionsmenu(menu menu) {     getmenuinflater().inflate(r.menu.main, menu);     return true; } 

this solve problems. more information read add search view action bar android documentation.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

javascript - Clean way to programmatically use CSS transitions from JS? -

android - send complex objects as post php java -