我正在使用来自 Android 设计库的新 TabLayout。我设法使用 tabLayout.setTabTextColors(colorstatelist)
设置了 textcolor statelist
如何使用styles.xml 实现相同的效果?
最佳答案
通过 XML 属性:
<android.support.design.widget.TabLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="fixed"
app:tabGravity="fill"
app:tabTextColor="@color/your_unselected_text_color"
app:tabSelectedTextColor="@color/your_selected_text_color"/>
此外,还有 tabIndicatorColor 或 tabIndicatorHeight 等属性用于进一步的样式设置。
在代码中:
tabLayout.setTabTextColors(
getResources().getColor(R.color.your_unselected_text_color),
getResources().getColor(R.color.your_selected_text_color)
);
由于这种旧方式自 API 23 起已被弃用,替代方案是:
tabLayout.setTabTextColors(
ContextCompat.getColor(context, R.color.your_unselected_text_color),
ContextCompat.getColor(context, R.color.your_selected_text_color)
);
关于android - TabLayout(Android 设计库)文本颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30909471/