13

I want to show and hide the action bar /toolbar as the Google Play store app. I am using sliding tabs on top and view pager to show the content of each tab. Here is the screenshot of Google play store app for the reference:

enter image description here enter image description here

My layout XML :

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

    <LinearLayout style="@style/HeaderBar"
        android:id="@+id/headerbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <include layout="@layout/toolbar_no_bg"
            android:id="@+id/toolbar_actionbar"/>

        <com.fauzie.sample.tabsspinner.widget.SlidingTabLayout
            android:background="@color/tab_background"
            android:id="@+id/sliding_tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
    </LinearLayout>

    <android.support.v4.view.ViewPager
        android:id="@+id/view_pager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@id/headerbar">

    </android.support.v4.view.ViewPager>

</RelativeLayout>

Thanks in advance.

1

3 Answers 3

5

Have a look at this:

https://github.com/flavienlaurent/NotBoringActionBar

There's a trick involved here. You'll need to:

  1. Wrap your layout in a list view
  2. Add a fake header with the same height as your action bar large header
  3. set your action bar overlay to true
  4. Translate the real header when the list moves (i.e. when the fake header is scrolled).

It's a little bit complicated at first but once you understand it, you see how smart and obvious it all is. The link will give you all you need I hope.

I myself used that link to implement it in my own app and it works great.

7
  • I tried with a scroll view first but it was really difficult to make it work. The problem with scroll view is that you'll have to make sure the "fake header" translates correctly yourself. With listview, the framework (i.e. the listview layout renderer) does that automatically but give it a go anyway and if it still doesn't work, there's always the listview option :).
    – kha
    Nov 6, 2014 at 8:59
  • @kha how can i change color of actionbar color when scrolled much? Aug 18, 2016 at 10:19
  • @DevendraSingh You shouldn't use this solution anymore. Nowadays, it's officially and natively supported in Android. Have a look at Coordinator Layout (good examples here: guides.codepath.com/android/…)
    – kha
    Aug 18, 2016 at 12:44
  • @kha i want to get the logo slide up and slide down while scrolling too Aug 19, 2016 at 4:57
  • @DevendraSingh I suggest you raise a separate SO question with your requirements and what you've done so far and where you're having problems and I'm sure people will help you. This solution was posted nearly 2 years ago and is no longer the recommended approach so you shouldn't use it anymore and should use the new layouts instead.
    – kha
    Aug 19, 2016 at 7:10
5

Checkout this library: https://github.com/ksoichiro/Android-ObservableScrollView

this will definitely help you

1
  • this is what I exactly looking for! Jul 28, 2015 at 9:16
3

Check this example to implement this with the new official Android Design Support Library:

https://github.com/chrisbanes/cheesesquare

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.