大家可能经常看到这种效果,当我们向上滑动的时候,标题栏会隐藏,当我们向下滑动的时候,标题栏会出现。下面就利用Android5.0的新特性来做出这种效果。
CoordinatorLayout、AppBarLayout、Toolbar、TabLayout
布局文件
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
app:theme="@style/ToolbarTheme"
app:title="发现"
app:titleTextAppearance="@style/ToolbarTheme"
app:titleTextColor="@color/white"/>
<android.support.design.widget.TabLayout
android:id="@+id/tabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
app:layout_collapseMode="pin"
app:tabGravity="fill"
app:tabIndicatorColor="@color/white"
app:tabInd