i creating searchview in android toolbar whenever, mention collapseactionview property inside menu.xml item like:-
<item android:id="@+id/search" android:title="@string/search_title" app:showasaction="always|collapseactionview" app:actionlayout="@layout/search_view_layout"/>
here search_view_layout.xml bellow:-
<?xml version="1.0" encoding="utf-8"?> <android.support.v7.widget.searchview xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="35dp"/>
in case searchview looking bellow image:-
in above image search icon doesn't appear. when click search title searchview open as:-
i don't understand,why not hide kart menu item, , not import style properties style.xml:-
<style name="searchviewstyle" parent="widget.appcompat.searchview"> <item name="querybackground">@color/white</item> <item name="searchicon">@drawable/search</item> <item name="goicon">@drawable/ic_search</item> <item name="android:textcolor">@color/black</item> <item name="android:layout_height">35dp</item> <item name="android:height">35dp</item>
but want design searchview bellow:-
any suggestion appreciable.
in menu add
<item android:id="@+id/search" android:icon="@drawable/ic_search" android:title="@string/search" yourapp:showasaction="ifroom|collapseactionview" yourapp:actionviewclass="android.support.v7.widget.searchview" />
in java class
searchmanager searchmanager = (searchmanager) context.getsystemservice(context.search_service); searchview searchview = (searchview) menu.finditem(r.id.search).getactionview(); searchview.setsearchableinfo(searchmanager.getsearchableinfo(((appcompatactivity) context).getcomponentname())); searchview.seticonifiedbydefault(false); searchview.setonquerytextlistener(this);
to apply style , add in style.xml
<style name="mytoolbar" parent="apptheme"> <item name="searchviewstyle">@style/searchstyle</item> </style> <style name="searchstyle" parent="widget.appcompat.searchview.actionbar"> <item name="queryhint">@string/search</item> <item name="searchicon">@null</item> <item name="colorcontrolactivated">@color/accent</item> <item name="colorcontrolnormal">@color/accent</item> </style>
and apply above theme in toolbar
<android.support.v7.widget.toolbar android:id="@+id/my_toolbar" android:layout_width="match_parent" android:minheight="?attr/actionbarsize" android:theme="@style/mytoolbar" android:layout_height="?attr/actionbarsize" app:layout_collapsemode="pin" > </android.support.v7.widget.toolbar>
Comments
Post a Comment