1

I'm trying to change the background color of a TabLayout, but so far everything I've tried doesn't work.

<com.google.android.material.tabs.TabLayout
        android:id="@+id/tabLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:tabIndicatorColor="#FF0000"
        app:tabSelectedTextColor="#FF0000"
        app:tabTextAppearance="@style/TabTextAppearance"
        app:tabTextColor="#FFFFFF">

        <com.google.android.material.tabs.TabItem
            android:id="@+id/tab_one"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Tab 1" />

        <com.google.android.material.tabs.TabItem
            android:id="@+id/tab_two"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Tab 2" />

I've tried using a drawable (selector) as advised here: https://stackoverflow.com/a/33230289/12221284

I've tried using a custom style extending the TabLayout style.

I've tried setting the XML attributes in my layout file directly.

Maybe I did something wrong, but nothing has worked so far and I don't understand why.

moeux
  • 191
  • 15
  • app:tabBackground should work. What color is displayed? – Gabriele Mariotti Oct 11 '20 at 08:16
  • @GabrieleMariotti My AppTheme background color is being displayed. I've customized my AppTheme Style in `styles.xml` by adding ` – moeux Oct 11 '20 at 12:35
  • @GabrieleMariotti I've removed my background customization, now the correct color is displayed. But by using this method I'd have to set the desired background for each root layout in every layout file individually. I feel like that setting my AppTheme background in `styles.xml` should work, even though it doesn't. – moeux Oct 11 '20 at 12:48

0 Answers0