我有这个代码用于更改标签布局文本的颜色,但它根本不起作用!
qazxsw poi不起作用,它不能将颜色变为白色。
app:tabTextColor
您可以自定义TabLayout的文本。
像这样从Java代码或XML创建TextView
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
app:tabIndicatorColor="@color/blue"
app:tabIndicatorHeight="5dp"
app:tabTextColor="@color/white" />
请确保将ID保留在此处,因为如果使用自定义TextView,TabLayout将检查此ID
然后从代码中膨胀此布局并在该TextView上设置自定义字体,并将此自定义视图添加到选项卡。
<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@android:id/text1"
android:layout_width="match_parent"
android:textSize="15sp"
android:textColor="@color/tabs_default_color"
android:gravity="center"
android:layout_height="match_parent"
/>
试试吧 -
for (int i = 0; i < tabLayout.getTabCount(); i++) {
//noinspection ConstantConditions
TextView tv=(TextView)LayoutInflater.from(this).inflate(R.layout.custom_tab,null)
tv.setTextColor(customColor)
tabLayout.getTabAt(i).setCustomView(tv);
}
使用此代码,它将有助于所有api级api 18到api 26
<android.support.design.widget.TabLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="fixed"
app:tabGravity="fill"
android:background="@color/colorWhite"
app:tabTextColor="@color/colorBlack"
app:tabSelectedTextColor="@color/colorPrimary"/>
当标签布局改变位置时,这将有助于我。