MiguelCatalan / MaterialSearchView

Cute library to implement SearchView in a Material Design Approach
http://miguelcatalan.info/2015/09/23/MaterialSearchView/
Apache License 2.0
3.84k stars 617 forks source link

how to show searchview inside toolbar when searchView.openSearch() is triggered ! #148

Open deshario opened 7 years ago

deshario commented 7 years ago

How to show MaterialSearchView inside Toolbar when we tap searchicon from toolbar! Can i replace all things in toolbar with materialsearchview when searchView.openSearch() is triggered !

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" xmlns:app="http://schemas.android.com/apk/res-auto" android:orientation="vertical">

<android.support.v7.widget.Toolbar
    android:id="@+id/contact_toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="?attr/colorPrimary"
    android:elevation="4dp"
    app:titleTextColor="@android:color/white"
    app:layout_scrollFlags="scroll|enterAlways"
    android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

<br.com.mauker.materialsearchview.MaterialSearchView
    android:id="@+id/search_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    style="@style/MaterialSearchViewStyle"/>

<ListView
    android:id="@+id/contacts_list"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

screenshot_20170326-011100

adeelhamza420 commented 7 years ago

i use it like this <FrameLayout android:id="@+id/toolbar_container" android:layout_width="match_parent" android:orientation="vertical" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_alignParentLeft="true" android:layout_alignParentStart="true">

    <android.support.v7.widget.Toolbar
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="#68b653"
        android:theme="@style/ThemeOverlay.AppCompat.Dark">
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <ImageView
                android:id="@+id/help"
                android:layout_width="30dp"
                android:layout_height="30dp"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true"
                android:layout_centerVertical="true"
                android:src="@drawable/drawer" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:layout_centerVertical="true"
                android:gravity="center"
                android:text="Map"
                android:textColor="#ffffff"
                android:textSize="18sp" />

        </RelativeLayout>
    </android.support.v7.widget.Toolbar>
    <com.miguelcatalan.materialsearchview.MaterialSearchView
        android:id="@+id/search_view"
        android:layout_width="match_parent"
        android:hint="Search for an Art Piece or Artist's Name"
        android:visibility="gone"
        style="@style/MaterialSearchViewStyle"
        android:layout_height="wrap_content"

        />
</FrameLayout>
RRethy commented 7 years ago

Above has right answer, wrap it in FrameLayout.