android - Search widget doesn't integrate with toolbar, when calling onSearchRequested() -
i created xml file in menu folder search item.
<item android:id="@+id/action_search" android:title="@string/search_hint" android:icon="@drawable/ic_magnify_white_24dp" app:showasaction="collapseactionview|ifroom" app:actionviewclass="android.support.v7.widget.searchview" />
i setup menu search function
@override public boolean oncreateoptionsmenu(menu menu) { // inflate menu items use in action bar menuinflater inflater = getmenuinflater(); inflater.inflate(r.menu.menu_option, menu); // associate searchable configuration searchview searchmanager searchmanager = (searchmanager) this.getsystemservice(context.search_service); searchview searchview = (searchview) menu.finditem(r.id.action_search).getactionview(); searchview.setsearchableinfo( searchmanager.getsearchableinfo(getcomponentname())); return super.oncreateoptionsmenu(menu); } @override public boolean onoptionsitemselected(menuitem item) { // handle presses on action bar items switch (item.getitemid()) { case r.id.action_search: //start search activity here onsearchrequested(); return true; default: return super.onoptionsitemselected(item); } }
the problem when i'm calling onsearchrequested(), search widget not integrate toolbar. see image: should (and when i'm not calling onsearchrequested(). thought documentation says, onsearchrequested needs called?): search widget loads twice.
any appreciated. thanks!
Comments
Post a Comment