在主题中定义 TabLayout 样式 [英] Define TabLayout style in theme

查看:40
本文介绍了在主题中定义 TabLayout 样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用中有两种不同风格的 TabLayout:

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>

如何为主题定义默认的 TabLayout 样式?我找不到任何应该使用哪个项目名称来构建我的主题的信息.我想以与添加列表视图相同的方式添加 TabLayout:

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>

推荐答案

对于支持库TabLayout,你可以在你的主题中设置tabStyle属性:

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>

这篇关于在主题中定义 TabLayout 样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆