首页 > 解决方案 > TabIndicatorColor not working in night theme.xml

问题描述

I am trying to set the tabIndicatorColor to a specified color depending on the device theme(That color in dark theme is white). The light theme works fine but in dark theme, the text in tabLayout is in white whereas the tabIndicatorColor does not turn white even though it is set to white. It shows a greyish color as the tabIndicatorColor.

night/themes.xml

<style name="Theme.News" parent="Theme.MaterialComponents.DayNight.NoActionBar">
    <!-- Primary brand color. -->
    <item name="colorPrimary">@color/darkGrey</item>
    <item name="colorPrimaryVariant">@color/lightGrey</item>
    <item name="colorOnPrimary">@color/white</item>
    <item name="colorSurface">@color/lightGrey</item>
    <item name="colorOnSurface">@color/white</item>

The tabLayout xml in activity_main.xml

<com.google.android.material.tabs.TabLayout
    
    android:background="?attr/colorPrimary"
    app:tabTextColor="?attr/colorSecondary"
    app:tabSelectedTextColor="?attr/colorOnPrimary"
    app:tabIndicatorColor="?attr/colorOnPrimary">

</com.google.android.material.tabs.TabLayout>

标签: androidandroid-studiothemesandroid-tablayout

解决方案


推荐阅读