用AppBarLayout包裹的子view会以一个整体的形式作为AppBar,从而具备统一的风格。
简单来说,只要控件是在AppBarLayout里面,那么就可以把这些控件通通当做标题栏。
以TabLayout和ViewPager的简单联用这个demo的布局为例,略作一下改动:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.canary.tablayoutviewpage.MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:text="你好,时间!"
android:textColor="#0f0"
android:textSize="30dp" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
效果展示如下:
1015

被折叠的 条评论
为什么被折叠?



