Styling text on TabLayout

自作多情 提交于 2019-12-06 22:10:13

问题


I'm trying to style the new TabLayout from android design library.

<style name="NavigationTab" parent="Widget.Design.TabLayout">
    <item name="tabBackground">@drawable/background_tab</item>
    <item name="tabIndicatorColor">@color/blue</item>
    <item name="tabTextAppearance">@style/NavigationTabTextAppeareance</item>
</style>

And the text is defined right here

<style name="NavigationTabTextAppeareance" parent="TextAppearance.Design.Tab">
      <item name="android:textColor">@color/primary_light</item>
      <item name="android:textSize">12sp</item>
</style>

But the selected tab is always black, how can I change it?


回答1:


set tabSelectedTextColor in NavigationTab like this:

<style name="NavigationTab" parent="Widget.Design.TabLayout">
    <item name="tabBackground">@drawable/background_tab</item>
    <item name="tabSelectedTextColor">@color/primary_light</item>
    <item name="tabIndicatorColor">@color/blue</item>
    <item name="tabTextAppearance">@style/NavigationTabTextAppeareance</item>
</style>

<style name="NavigationTabTextAppeareance" parent="TextAppearance.Design.Tab">
      <item name="android:textColor">@color/primary_light</item>
      <item name="android:textSize">12sp</item>
</style>



回答2:


If you just have to give different text color then there is direct option by using app:tabTextColor for unselected and app:tabSelectedTextColor for selected tab text like in example .

<android.support.design.widget.TabLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:tabTextColor="#607D8B"
            app:tabSelectedTextColor="#FFFFFF"/>


来源:https://stackoverflow.com/questions/31249048/styling-text-on-tablayout

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!