TabLayout+viewpaper+fragment设置字体大小,以及自定义添加下划线

首先设置app:tabIndicatorHeight="0dp"
设置默认的字体大小以及颜色
app:tabTextAppearance="@style/TabText"
<style name="TabText">
<item name="android:textSize">15sp</item>
<item name="android:textColor">#666666</item>
</styl
自定义tab
//custrom_tab.xml
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="45dp"
android:orientation="vertical">
<TextView
android:id="@+id/t_tab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textSize="18sp"
android:textColor="#8B2316"
android:gravity="center"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_gravity="bottom"
android:background="#8B2316"/>

</LinearLayout>


tabs.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
@Override
public void onTabSelected(TabLayout.Tab tab) {
                tab.setCustomView(R.layout.custrom_tab);
                TextView textView =tab.getCustomView().findViewById(R.id.t_tab);
textView.setText(tab.getText());


}

@Override
public void onTabUnselected(TabLayout.Tab tab) {
tab.setCustomView(null);

}

@Override
public void onTabReselected(TabLayout.Tab tab) {

}
});
posted @ 2021-09-09 17:31  only_books  阅读(339)  评论(0编辑  收藏  举报