0

I have a tabbedactivity layout, but i need to customize that layout for swipe between 2 activities, like this.

I cant change the background color, just the line indicator. Anyone knows how can i do that?

<android.support.design.widget.AppBarLayout
    android:id="@+id/appbarBottom"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom"
    android:paddingTop="@dimen/appbar_padding_top"
    android:theme="@style/AppTheme.AppBarOverlay">

    <android.support.design.widget.TabLayout
        android:id="@+id/tabsBottom"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

</android.support.design.widget.AppBarLayout>

thx!

Darush
  • 11,403
  • 9
  • 62
  • 60
Flavio Luiz
  • 37
  • 1
  • 7

1 Answers1

0

To change the background color of an item selected you'll have to use app:tabBackground and set custom selector.

tab_selector:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:drawable="@color/colorPrimaryDark" android:state_selected="true"/>
    <item android:drawable="@color/colorPrimary"/>

</selector>

TabLayout:

<android.support.design.widget.TabLayout
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:tabBackground="@drawable/tab_selector">...
Man
  • 2,720
  • 2
  • 13
  • 21
  • I have other problem. Now the AppBarLayout is on the TabLayout, and i have different colors for both. Its not possible to change a first half to medium red and other half to dark red (OF APPBARLAYOUT). – Flavio Luiz Jun 24 '18 at 15:03