TabLayout
1. 自定义长度
app:tabIndicator="@drawable/shape_line_white" app:tabIndicatorColor="@android:color/white" <?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <item android:gravity="center"> <shape> <size android:width="@dimen/dp_67" android:height="@dimen/dp_3" /> </shape> </item> </layer-list>
2. 点击前判断
binding.tabLayoutTips.apply { val first = newTab().setText("个人业绩") addTab(first) addTab(newTab().setText("团队业绩").apply { view.setOnClickListener { dialogTipsForDisable(mContext,supportFragmentManager) AppContext.mHandler.postDelayed({ first.select() },5) } }) }
3. 字体选上加粗或者其他操作
binding.tabLayoutTips.addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener { override fun onTabSelected(tab: TabLayout.Tab) { tab.view[1].let { (it as TextView).paint.isFakeBoldText = true } } override fun onTabUnselected(tab: TabLayout.Tab) { tab.view[1].let { (it as TextView).paint.isFakeBoldText = false } } override fun onTabReselected(tab: TabLayout.Tab?) { } })