0

Code

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 
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"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.appmaster.akash.messageplus.HomeScreen"
tools:showIn="@layout/app_bar_main">

<!-- Note : This is the container Frame Layout for all the fragmetns-->
<FrameLayout
    android:background="@color/black"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/mainFrame">

<!--<FrameLayout-->
    <!--android:layout_width="match_parent"-->
    <!--android:layout_height="?attr/actionBarSize"-->
    <!--android:id="@+id/frame">-->
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    <android.support.design.widget.TabLayout
        android:id="@+id/sliding_tabs"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:elevation="5dp"
        android:background="@color/black"
        app:tabTextColor="@color/white"
        app:tabSelectedTextColor="@color/grey"
        app:theme="@style/ThemeOverlay.AppCompat.Dark"
        app:layout_scrollFlags="scroll|enterAlways"
        tools:ignore="UnusedAttribute" />

    <RelativeLayout
        android:layout_below="@+id/sliding_tabs"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <android.support.v4.view.ViewPager
            android:id="@+id/viewpager"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@android:color/white"></android.support.v4.view.ViewPager>

    </RelativeLayout>
    </RelativeLayout>
</FrameLayout>
<!--</FrameLayout>-->

How do i change the background color of the selected tab??? I know how to change the selected text color like in the code... but how do i do it to background color? because im using icons instead of text and i dont think i can change the icon color so i just want to change the background color of the selected tab

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
  • you can use custom tabs with custom layout and in listner can change any background or icons – Vidhi Dave Oct 06 '18 at 11:55
  • try out android:background="@color/black" with selector – Rahul Oct 06 '18 at 12:04
  • Does it have to be custom? if yes can i get the code please @VishvaDave –  Oct 06 '18 at 12:04
  • https://guides.codepath.com/android/google-play-style-tabs-using-tablayout or even you can search on google for custom tabs inflate in android.. you will get many ideas.. or if you don't want a custom you can create a selector for this.. – Vidhi Dave Oct 06 '18 at 12:09
  • Possible duplicate of [How do I change a tab background color when using TabLayout?](https://stackoverflow.com/questions/31640563/how-do-i-change-a-tab-background-color-when-using-tablayout) – Mohamed Mohaideen AH Oct 06 '18 at 13:14

0 Answers0