samedi 26 décembre 2020

How to change color of Material Design Tab item when selected

I've got simple tabLayout:

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

        android:id="@+id/tab_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:tabMode="scrollable">

        <com.google.android.material.tabs.TabItem
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/home" />
        <com.google.android.material.tabs.TabItem
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/all_charts" />
        <com.google.android.material.tabs.TabItem
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/low_score" />
        <com.google.android.material.tabs.TabItem
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/big_score" />

When user select particular tab, it's color's changing, how can I change it? I've tried by implementing my own style like this:

   <style name="Widget.MyApp.TabLayout" parent="Widget.MaterialComponents.TabLayout">
    <item name="background">@color/white</item>
    <item name="textAppearanceCaption">@color/dark</item>
</style>

And then in main TabLayout:

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

        android:id="@+id/tab_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        style="@style/Widget.MaterialComponents.TabLayout"
        app:tabMode="scrollable">

This solutions is not working.

Aucun commentaire:

Enregistrer un commentaire