一 丶在Java代码中加上一句话:
tablayout.setupWithViewPager(viewpager);
二 丶是把 TabLayout 放进 ViewPager 控件中 系统会自动回调 setupWithViewPager () 方法
<android.support.v4.view.ViewPager
android:id="@+id/vp_FindFragment_pager"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.TabLayout
android:id="@+id/tab_FindFragment_title"
android:background="@color/colorPrimary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabIndicatorColor="@color/colorAccent"
app:tabSelectedTextColor="@color/colorwhe"
app:tabTextColor="@color/colorwh">
</android.support.design.widget.TabLayout>
</android.support.v4.view.ViewPager>
另外 和ViewPager联动, 需要重写adapter 的getPageTitle,否则无法显示TabLayout上的标签