<com.google.android.material.tabs.TabLayout
android:id="@+id/tablayout"
android:layout_width="wrap_content"
android:layout_height="80dp"
app:tabTextAppearance="@style/vpa_custom_tablayout_style"
//tab按钮文字颜色
app:tabTextColor="@color/black_6017191E"
//tab按钮选中时的文字颜色
app:tabSelectedTextColor="@color/black_17191E"
app:tabMode="scrollable"
app:tabMinWidth="180dp"
app:tabMaxWidth="300dp"
app:tabPadding="0dp"
android:longClickable="false"
app:tabIndicator="@mipmap/ic_vpa_custom_tab_bottom"
//下划线位置
app:tabIndicatorGravity="bottom"
app:tabIndicatorAnimationMode="linear"
app:tabIndicatorHeight="10dp"
app:tabIndicatorColor="@color/blue_3292F5"
//下划线是否占据tab整个宽度; false:长度和文字同步
app:tabIndicatorFullWidth="false"
android:background="@color/white_ECEFF4"
android:layout_marginStart="20dp"
>
<com.google.android.material.tabs.TabItem
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="@string/vpa_custom_tab_1"
/>
<com.google.android.material.tabs.TabItem
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="@string/vpa_custom_tab_2"
/>
</com.google.android.material.tabs.TabLayout>
for (int i = 0; i < tabLayout.getTabCount(); i++) {
TabLayout.Tab tab = tabLayout.getTabAt(i);
if(tab != null) {
//去掉长按tab按钮会出现的toast弹框
tab.view.setLongClickable(false);
tab.view.setTooltipText(null);
//去掉点击tab按钮会出现的黑色背景
tab.view.setBackground(null);
}
}