How to change selected Tab Text color using TabLayout from code in Android?

how to change selected tab background color in android
tablayout text color android
change tab icon color when selected android
how to change tab text font in android
android-tablayout custom view selected text color
change text color on selection android
android tablayout custom indicator
com.google.android.material.tabs.tablayout text size

I'm using android.support.widget.TabLayout to make a Tab view, and I want to change the selected tabs text color from code (not from xml or by styling). How can I do this ?

If you are using the design support library add this code to your tab activity.

tabLayout.setSelectedTabIndicatorColor(Color.parseColor("#FF0000"));
tabLayout.setSelectedTabIndicatorHeight((int) (5 * getResources().getDisplayMetrics().density));
tabLayout.setTabTextColors(Color.parseColor("#727272"), Color.parseColor("#ffffff"));

This will set the tab text color as well as tab indicator color in your tab activity.

Change tabs text color in TabLayout to different colors, I had tried on this too, but my code was not using tabHost. My solution based on @Bhavesh Misri's suggestion: ViewGroup vg = (ViewGroup)  In this android programming source code example, we are going to change TabLayout menu item text color in Android. You can copy and adopt this source code example to your android project without reinventing the wheel. Below is a step by step source code to change TabLayout menu item text color in Android.

It's so simple using XML. Just add the following 2 attributes in your tab layout.

app:tabSelectedTextColor="@color/color_primary_text"
app:tabTextColor="@color/color_secondary_text"

So, your code would look something like this.

<android.support.design.widget.TabLayout
    android:id="@+id/tab_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentStart="true"
    android:layout_gravity="bottom"
    android:background="@color/button_background"
    android:fillViewport="true"
    app:tabBackground="@drawable/fixed_bottom_button"
    app:tabIndicatorColor="@color/color_primary_text"
    app:tabMode="fixed"
    app:tabSelectedTextColor="@color/color_primary_text"
    app:tabTextColor="@color/color_secondary_text" />

Custom views at TabLayout with highlighted text style at the selected , tab view. I will assume that you are already familiar with creating a ViewPager​… Custom views at TabLayout with highlighted text style at the selected tab. Petar Jonceski. Follow <item name="android:textColor">@color/​primaryTextColor87</item> </style> We need to create a style in xml and set it at the TabLayout. How To Change Selected Tab Text Color In Android

Please check out following answer

 tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
        @Override
        public void onTabSelected(TabLayout.Tab tab) {
            View view = tab.getCustomView();
            RelativeLayout relativeLayout = (RelativeLayout) view.findViewById(R.id.layout_background);
            relativeLayout.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.white));
            TypefacedTextView selectedText = (TypefacedTextView) view.findViewById(R.id.txt_tab_name);
            selectedText.setTextColor(ContextCompat.getColor(getActivity(), R.color.colorPrimary));

        }

        @Override
        public void onTabUnselected(TabLayout.Tab tab) {
            View view = tab.getCustomView();
            RelativeLayout relativeLayout = (RelativeLayout) view.findViewById(R.id.layout_background);
            relativeLayout.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.colorPrimary));
            TypefacedTextView selectedText = (TypefacedTextView) view.findViewById(R.id.txt_tab_name);
            selectedText.setTextColor(ContextCompat.getColor(getActivity(), R.color.white));
        }

        @Override
        public void onTabReselected(TabLayout.Tab tab) {

        }
    });

where tabLayout is object of TabLayout Class

Android TabLayout Selected Tab Text Color, Android TabLayout Selected Tab Text Color. Android TabLayout provides a horizontal layout to display tabs on the screen. Add the following dependency to your app module's build. In the activity_main. Create tab_background. Add colors in the colors. Add theme in styles. Create FragmentAdapter. In MainActivity. How to change selected Tab Text color using TabLayout from code in Android? (4) I'm using android.support.widget.TabLayout to make a Tab view, and I want to change the selected tabs text color from code (not from xml or by styling).

I know this might be a bit late but here is more simpler code :

tabLayout.setTabTextColors(getResources().getColor(R.color.blue_200), getResources().getColor(R.color.white));

first value is the default text color, 2nd value is the selected tab text color.

Google Play Style Tabs using TabLayout, Prior to Android "M", the easiest way to setup tabs with Fragments was to use ActionBar Tabs as layout for the fragment which will be displayed on screen when a particular tab is selected: Set the ViewPager on the TabLayout to connect the pager with the tabs. tabTextColor, @color/blue, Color of the text on the tab  How to change tab color in TabLayout : Create a drawable, tab_selected_background, that will be use as the background for the selected tab: Create a selector, tab_selector that will be used as the background for tab layout: Now finally create the tab layout and use the selector that we've just create as the background of the tabLayout.

tabLayout.setSelectedTabIndicatorColor(Color.parseColor("#FF0000"));
tabLayout.setSelectedTabIndicatorHeight((int) (5 * getResources().getDisplayMetrics().density));
tabLayout.setTabTextColors(Color.parseColor("#727272"), Color.parseColor("#ffffff"));

TabLayout, Population of the tabs to display is done through TabLayout. From there you can change the tab's label or icon via setText(int) and setIcon(int) respectively Gets the text colors for the different states (normal, selected) used for the tabs. Content and code samples on this page are subject to the licenses  Here you pass 2 arguments: Android getSupportFragmentManager() and the total number of tabs in Android Tablayout. 24- Now you can use pageAdapter as the adapter for Android ViewPager. viewPager.setAdapter(pageAdapter); 25- Build and run the app to see the progress. Android Tablayout example with tabs. (Large preview) 26- Now you got the swipe

Tab Layout, scrolling behavior,; (swipe) gestures,; tab selection,; animations,; and alignment. To use a TabLayout with a static number of tabs, define each tab as a  If you are using the latest android application then you have noticed that now days android is following a design pattern. This is material design and it came with Android Lollipop (5.0). Though we can still use this design pattern for the older versions (>4.0) by using the support libraries. One of the component of material design is TabLayout.

Change selected tab text size android, First Tab selected with specified color given to it while other tabs are unselected. I'm using a tab layout and I need to disable tab layout text uppercase and change May 06, 2013 · This post will walk you through Android ListView Tutorial for  2. addTab(Tab tab): This method is used to add a tab in the TabLayout. By using this method we add the tab which we created using newTab() method in the TabLayout. The tab will be added at the end of the list and If it is the first tab to be added then it will become the selected tab.

How to specify different text color for the selected and unselected tab , I want use different text color for the selected and unselected tab indicator. together to host and review code, manage projects, and build software together. http://developer.android.com/guide/topics/resources/color-list-resource.html from the library, where the drawables are changed for colors. I use  Questions: I’m using a TabLayout with a ViewPager and I’m wondering how I can most efficiently change the color of the icon of the selected tab in the TabLayout. A perfect reference for how this is implemented is Google’s Youtube app. On the main page, there are four icons that are colored dark gray. When

Comments
  • its android.support.design.widget.TabLayout
  • stackoverflow.com/questions/5577688/…
  • actually i m asking using TabLayout not TabHost
  • thank you help but i m asking to change the text color of current tab
  • yes the third line's first parameter is for the default color and the second parameter will set the mentioned color to the selected tab. ie for the non-selected tab the color will be #727272 and for selected tab the color will be #ffffff
  • if you can please accept the answer. glad this helped you
  • not working. I tried with creating style also but none worked
  • @Raykud Yeah, you are right. But at that time, I was looking for a solution using XML and didn't found any. So, I posted my solution for anyone looking for the same in the future.
  • This variant suits better if you have a custom view for tab item.
  • Might be useful for anyone who is looking for the same issue :)