<com.google.android.material.tabs.TabLayout
android:id="@+id/tbLDownloadInfo"
android:layout_width="match_parent"
android:layout_height="@dimen/dp_48"
android:background="@color/colorPrimary"
app:tabIndicatorColor="@color/color_146EFF"
app:tabTextAppearance="@style/CustomTabLayoutTextAppearance"
app:tabTextColor="@color/color_7a191a2c"
app:tabSelectedTextColor="@color/color_1B1B1F"
app:layout_constraintTop_toBottomOf="@+id/rlToolBar"
app:tabIndicatorHeight="@dimen/dp_3"
app:tabMode="fixed">
<com.google.android.material.tabs.TabItem
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="@string/str_downloading"
/>
<com.google.android.material.tabs.TabItem
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="@string/str_downloaded"
/>
</com.google.android.material.tabs.TabLayout>
private fun setTabView() {
val tabProgress = tbLDownloadInfo.getTabAt(0)
tabProgress?.setCustomView(R.layout.item_tab_downloading)
val tabFinished = tbLDownloadInfo.getTabAt(1)
tabFinished?.setCustomView(R.layout.item_tab_finished)
}
tbLDownloadInfo.getTabAt(pos)?.select()//切换选中效果
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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="@dimen/dp_48">
<androidx.appcompat.widget.LinearLayoutCompat
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.appcompat.widget.AppCompatImageView
android:layout_width="@dimen/dp_24"
android:layout_height="@dimen/dp_24"
android:layout_gravity="center_vertical"
android:scaleType="fitXY"
app:srcCompat="@drawable/select_tab_downloading_image" />
<com.xvideostudio.allrounddownload.widget.RobotoMediumTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/dp_8"
android:gravity="center"
android:layout_gravity="center_vertical"
android:text="@string/str_downloading"
android:textColor="@color/select_tab_text_color"
android:textSize="@dimen/sp_15" />
</androidx.appcompat.widget.LinearLayoutCompat>
</androidx.constraintlayout.widget.ConstraintLayout>
网友评论