Как изменить цвет TabLayout / Tabs, изменив тему? Я использую светлый и темный режим, но таблейтаут всегда светлый. LinearLayout с TextView и ImageView также не меняет тему.
MainActivity. xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:forceDarkAllowed="true"
android:background="?attr/backgroundColor"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="?attr/backgroundColor"
android:padding="15dp">
<TextView
android:id="@+id/toolbarTitle_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Toolbar"
android:textColor="?attr/textColor"
android:textSize="16sp" />
<ImageView
android:id="@+id/profile_img"
android:layout_width="30dp"
android:layout_height="30dp"
android:src="@drawable/ic_account_circle_black_24dp" />
</LinearLayout>
<com.google.android.material.tabs.TabLayout
android:id="@+id/tablayout"
style="?attr/myTabStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<com.google.android.material.tabs.TabItem
android:id="@+id/homeTab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Početna" />
<com.google.android.material.tabs.TabItem
android:id="@+id/albumsTab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Albumi" />
<com.google.android.material.tabs.TabItem
android:id="@+id/savedTab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Spremljeno" />
</com.google.android.material.tabs.TabLayout>
<androidx.viewpager.widget.ViewPager
android:id="@+id/viewPager"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
У меня есть два стиля для тем. И я называю их стилем? Attr / myTabStyle. xml:
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="backgroundColor">@color/lightBackground</item>
<item name="cardBackground">@color/LightGray</item>
<item name="textColor">@color/lightThemeText</item>
<item name="textColorSecond">@color/gray</item>
<item name="textColorReverse">@color/white</item>
<item name="categoryBox">@color/gray</item>
<item name="tintColor">@color/lightThemeText</item>
<item name="headerColor">@color/colorPrimaryLight</item>
<item name="navBarColor">@color/colorPrimaryLight</item>
<item name="colorControlNormal">#c5c5c5</item>
<item name="colorControlActivated">@color/white</item>
<item name="colorControlHighlight">@color/white</item>
<item name="myTabStyle">@style/TabLayoutLight</item>
<item name="android:windowAnimationStyle">@style/WindowAnimationTransition</item>
<item name="onOffSwitch">@style/OnOffSwitch</item>
</style>
<style name="DarkTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="backgroundColor">@color/darkBackground</item>
<item name="cardBackground">@color/darkGray</item>
<item name="textColor">@color/darkThemeText</item>
<item name="textColorSecond">@color/gray</item>
<item name="tintColor">@color/darkThemeText</item>
<item name="headerColor">@color/darkGray</item>
<item name="navBarColor">@color/darkGray</item>
<item name="colorControlNormal">#c5c5c5</item>
<item name="colorControlActivated">@color/greenButton</item>
<item name="colorControlHighlight">@color/white</item>
<item name="myTabStyle">@style/TabLayoutDark</item>
<item name="android:windowAnimationStyle">@style/WindowAnimationTransition</item>
<item name="onOffSwitch">@style/OnOffSwitch</item>
</style>
<style name="OnOffSwitch" parent="Theme.AppCompat.Light">
<!-- active thumb & track color (30% transparency) -->
<item name="colorControlActivated">@color/ActiveSwitch</item>
<!-- inactive thumb color -->
<item name="colorSwitchThumbNormal">@color/inActiveSwitch</item>
<!-- inactive track color (30% transparency) -->
<item name="android:colorForeground">#42221f1f
</item>
</style>
<style name="WindowAnimationTransition">
<item name="android:windowEnterAnimation">@android:anim/fade_in</item>
<item name="android:windowExitAnimation">@android:anim/fade_out</item>
</style>
<style name="TabLayoutLight" parent="Widget.MaterialComponents.TabLayout">
<item name="tabIndicatorColor">?attr/colorAccent</item>
<item name="tabIndicatorHeight">4dp</item>
<item name="tabPaddingStart">6dp</item>
<item name="tabPaddingEnd">6dp</item>
<item name="tabBackground">@color/lightBackground</item>
<item name="tabTextAppearance">@color/lightThemeTextSecond</item>
<item name="tabSelectedTextColor">@color/lightThemeText</item>
</style>
<style name="TabLayoutDark" parent="Widget.MaterialComponents.TabLayout">
<item name="tabIndicatorColor">?attr/colorAccent</item>
<item name="tabIndicatorHeight">4dp</item>
<item name="tabPaddingStart">6dp</item>
<item name="tabPaddingEnd">6dp</item>
<item name="tabBackground">@color/darkBackground</item>
<item name="tabTextAppearance">@color/darkThemeTextSecond</item>
<item name="tabSelectedTextColor">@color/darkThemeText</item>
</style>
</resources>
Светлая тема
Темная тема
Любые предложения?