Android Persistent Search Bar in Toolbar

nerras picture nerras · Jan 28, 2016 · Viewed 17.3k times · Source

I am fairly new to Android development. I went through the Google Udacity course and am currently trying to code an app. Specifically, I'm trying to switch over my current app (written in QT) to native Android.

What I am trying to do is making something similar to this:

http://i.stack.imgur.com/Exm2y.png

Which was taken from the Material Design - Persistent search, with navigation drawer question on the User Experience Stack Exchange.

I can do the top part, but I cannot figure out how to get the persistent search bar at the bottom. I've been trying different solutions (custom theme for activitybar and toolbar), but have not been able to get something even remotely close. Could someone help me out with this?

Answer

user1153174 picture user1153174 · Sep 16, 2016

just need to put all together inside AppBarLayout. Toolbar and any library for persisten search. Here is very useful, so finally set your layout_height for AppBarLayout. something like this

<android.support.design.widget.AppBarLayout
    android:id="@id/app_bar_layout"
    android:layout_width="match_parent"
    android:layout_height="@dimen/margin_130"
    android:background="@drawable/bg_tab_degraded"
    android:theme="@style/ThemeOverlay.AppCompat.Dark">

    <android.support.v7.widget.Toolbar
        android:id="@id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="@drawable/bg_tab_degraded"
        app:layout_scrollFlags="scroll|enterAlways"
        />

    <com.arlib.floatingsearchview.FloatingSearchView
        android:id="@+id/floating_search_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/bg_tab_degraded"
        app:floatingSearch_searchBarMarginLeft="@dimen/margin_20"
        app:floatingSearch_searchBarMarginTop="@dimen/margin_5"
        app:floatingSearch_searchBarMarginRight="@dimen/margin_20"
        app:floatingSearch_searchHint="Search..."
        app:floatingSearch_suggestionsListAnimDuration="250"
        app:floatingSearch_showSearchKey="false"
        app:floatingSearch_leftActionMode="showSearch"
        app:floatingSearch_menu="@menu/main"
        app:floatingSearch_close_search_on_keyboard_dismiss="true"/>



</android.support.design.widget.AppBarLayout>

I hope, It will help you. Good luck.