0

I am trying to use the AppBarLayout with Toolbar and Tabs so that Toolbar becomes hidden when user scrolls.

I tried to do it exactly the same way as Cheesesquare example but it still doesn't work.

Here is my XML code:

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.izzivizzi.avant2go.activities.ACLoginActivity"
android:background="@color/activity_background_light">

<android.support.design.widget.AppBarLayout
    android:id="@+id/appbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:minHeight="?attr/actionBarSize"
        android:background="@color/green"
        android:theme="@style/AppTheme"
        app:layout_scrollFlags="scroll|enterAlways">

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/margin_big"
            android:layout_marginBottom="@dimen/margin_big"
            android:orientation="vertical"
            android:layout_gravity="center">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:textColor="@color/white"
                android:textSize="30sp"
                android:text="@string/avantcar"/>

            <View
                android:layout_width="300dp"
                android:layout_height="1dp"
                android:layout_marginTop="5dp"
                android:background="@color/white" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="5dp"
                android:layout_gravity="center"
                android:textColor="@color/white"
                android:textSize="18sp"
                android:text="@string/main_slogan"/>

        </LinearLayout>

    </android.support.v7.widget.Toolbar>

    <android.support.design.widget.TabLayout
        android:id="@+id/tabLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/green"
        android:layout_below="@id/toolbar"
        app:tabIndicatorColor="@color/primary"
        app:tabSelectedTextColor="@color/white"
        app:tabTextColor="@color/primary"/>

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

<android.support.v4.view.ViewPager
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/viewPager"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@+id/appbar"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

</RelativeLayout>

I've also tried replacing RelativeLayout with CoordinatorLayout but it doesn't work.

Guy
  • 6,414
  • 19
  • 66
  • 136
  • What does your tab contain? ListView?? – Raghunandan Aug 03 '15 at 12:17
  • @Raghunandan tab contains a ScrollView with LinearLayout (which has a bunch of EditTexts etc.) – Guy Aug 03 '15 at 12:20
  • You may want to take a look @ https://github.com/nuuneoi/Lab-Android-DesignLibrary/blob/master/app/src/main/res/layout/activity_main.xml. Also the github project has a working code and the blog with explanation @ http://inthecheesefactory.com/blog/android-design-support-library-codelab/en – Raghunandan Aug 03 '15 at 12:24
  • Thanks! I got it to work with the help of this sample. All I had to do was use CoordinatorLayout instead of RelativeLayout and NestedScrollView instead of normal ScrollView inside fragment. – Guy Aug 03 '15 at 12:55

0 Answers0