I don't know why even if I make these changes the background of my tabLayout is still white and the one I want to put is a gray more specifically the 3D3D3D
. It is just the indicator of the tab since the background of the fragment does turn gray
<com.google.android.material.tabs.TabLayout
android:id="@+id/tab_layout"
tabmode="fixed"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/grey"
app:tabBackground="@color/grey"
app:tabIndicator="@drawable/tab_indicator"
app:tabIndicatorAnimationMode="elastic"
app:tabIndicatorColor="@color/white"
app:tabIndicatorHeight="3dp"
app:tabSelectedTextColor="@color/white" />
<androidx.viewpager2.widget.ViewPager2
android:id="@+id/view_pager2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/tab_layout"
android:layout_marginTop="-1dp"
android:background="@color/@color/grey" />
This is how it appears in the app
the attribute
tabIndicator
is used to give the tabIndicator a shape (rounded edges, etc) and some gradient if desired. It depends on how you have armed it to the drawable, you can overwrite the color that you indicate in the attributetabIndicatorColor
. One solution is to remove the line:Another option is to give it the color inside the drawable and set the attribute as follows:
Cheers!
It is supposed that when selecting the selector you can paint it with one color and when the element is deselected you paint it with another color, to do this you must use a selector, create one in a file
tab_selector.xml
and save it in the directory/drawable
of your project:now this
selector
use it in yourTabLayout