Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
399 views
in Technique[技术] by (71.8m points)

android - Define TabLayout style in theme

I have two different styles of TabLayout in my app:

<style name="TabLayoutPower" parent="Widget.Design.TabLayout">
    <item name="tabSelectedTextColor">@android:color/white</item>
    <item name="tabTextColor">@android:color/white</item>
</style>

<style name="TabLayoutFree" parent="Widget.Design.TabLayout">
    <item name="tabSelectedTextColor">@android:color/black</item>
    <item name="tabTextColor">@android:color/black</item>
</style>

How can I define the default TabLayout style for a theme? I cannot find any info which item name should I use to build my theme. I'd like to add the TabLayout the same way I added my listview:

<style name="Free" parent="Theme.AppCompat.Light.DarkActionBar">
        <item name="colorPrimary">@color/black</item>
        <item name="colorPrimaryDark">@color/black</item>
        <item name="colorAccent">@color/main_red</item>
        <item name="android:windowBackground">@color/main_bg_light</item>
        <item name="android:listViewStyle">@style/MyListView</item>
    </style>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

For Support Library TabLayout, you can set tabStyle attribute in your theme:

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- ... -->
    <item name="tabStyle">@style/AppTheme.TabLayout</item>
</style>

<style name="AppTheme.TabLayout" parent="Widget.Design.TabLayout">
    <item name="tabSelectedTextColor">@android:color/white</item>
    <item name="tabTextColor">@android:color/white</item>
</style>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...