Search code examples
androidmaterial-designandroid-appcompatandroid-actionbar-compatandroid-design-library

Android How make the same action bar?


Please help me. How i can make the same action bar?(Without using the observablescrollview library) http://material-design.storage.googleapis.com/publish/material_v_4/material_ext_publish/0B6Okdz75tqQsR1lZQUxtWFRFMEU/patterns-scrolling-techniques_standard_appbar_xhdpi_004.webm

Or same action bar as in PlayMarket app. I mean the same hiding and appearance on scrolling.


Solution

  • You can use the Design support library.

    Just add this dependency in your build.gradle file:

    compile 'com.android.support:design:23.1.0'
    

    Then use something like this:

    <android.support.design.widget.CoordinatorLayout>
    
        <android.support.design.widget.AppBarLayout>
                <android.support.v7.widget.Toolbar
                    android:layout_height="?attr/actionBarSize"
                    app:layout_scrollFlags="scroll|enterAlways"/>
    
        </android.support.design.widget.AppBarLayout>
    
        <android.support.v7.widget.RecyclerView
            app:layout_behavior="@string/appbar_scrolling_view_behavior">
    
    </android.support.design.widget.CoordinatorLayout>
    

    The app:layout_behavior="@string/appbar_scrolling_view_behavior" will add a behavior to the view, which can be listened by the AppBarLayout to animate its children.

    The app:layout_scrollFlags="scroll|enterAlways" line will cause that the Toolbar will scroll of the screen when user scrolls down the list.

    You can find more info in the official blog.