'Android Persistent Search Bar in Toolbar

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?



Solution 1:[1]

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.

Solution 2:[2]

You can try PersistentSearch

search = (SearchBox) findViewById(R.id.searchbox);
for(int x = 0; x < 10; x++){
    SearchResult option = new SearchResult("Result " + Integer.toString(x), getResources().getDrawable(R.drawable.ic_history));
    search.addSearchable(option);
}       
search.setLogoText("My App");
search.setMenuListener(new MenuListener(){

        @Override
        public void onMenuClick() {
            //Hamburger has been clicked
            Toast.makeText(MainActivity.this, "Menu click", Toast.LENGTH_LONG).show();              
        }

    });
search.setSearchListener(new SearchListener(){

    @Override
    public void onSearchOpened() {
        //Use this to tint the screen
    }

    @Override
    public void onSearchClosed() {
        //Use this to un-tint the screen
    }

    @Override
    public void onSearchTermChanged() {
        //React to the search term changing
        //Called after it has updated results
    }

    @Override
    public void onSearch(String searchTerm) {
        Toast.makeText(MainActivity.this, searchTerm +" Searched", Toast.LENGTH_LONG).show();

    }

    @Override
    public void onResultClick(SearchResult result){
        //React to a result being clicked
    }


    @Override
    public void onSearchCleared() {

    }

});

Also check https://github.com/UsherBaby/SearchView-1

enter image description here

Solution 3:[3]

You can try this.i have used this github library

https://github.com/arimorty/floatingsearchview

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 user1153174
Solution 2
Solution 3 Syed Danish Haider