一个fragment通过tab集合的数量来动态创建
效果图(这里就一个fragment)
1导入依赖
implementation 'com.android.support:design:28.0.0'
2main布局文件,design版本低的话tabIndicatorFullWidth方法可能会出现找不到 ,实现的是下划线和内容宽度一致
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="lingniu.renhekeji.com.myapplication.MainActivity">
<android.support.design.widget.TabLayout
android:id="@+id/tabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabIndicatorColor="#EA5404"
app:tabIndicatorHeight="3dp"
app:tabIndicatorFullWidth="false"
app:tabTextAppearance="@style/TabLayoutTextStyle"
app:tabSelectedTextColor="#EA5404"