How to Change the Color of the Tabs Indicator Text in Android

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

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.

how to change the color of the tabs indicator text in android?

Style it
in your custom theme change

<item name="android:tabWidgetStyle">@android:style/Widget.TabWidget</item> 

and

<style name="Widget.TabWidget">
<item name="android:textAppearance">@style/TextAppearance.Widget.TabWidget</item>
<item name="android:ellipsize">marquee</item>
<item name="android:singleLine">true</item>
</style>

<style name="TextAppearance.Widget.TabWidget">
<item name="android:textSize">14sp</item>
<item name="android:textStyle">normal</item>
<item name="android:textColor">@android:color/tab_indicator_text</item>
</style>

How to change material viewpager tab indicator text color?

For changing colour of indicator programmatically.

tabLayout.setSelectedTabIndicatorColor(Color.parseColor("#898989"));

How to Change Text Color of tab Layout?

You can customize your TabLayout's text.

Create a TextView from Java Code or XML like this

<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@android:id/text1"
android:layout_width="match_parent"
android:textSize="15sp"
android:textColor="@color/tabs_default_color"
android:gravity="center"
android:layout_height="match_parent"
/>

Make sure to keep the id as it is here because the TabLayout check for this ID if you use custom TextView

Then from code inflate this layout and set the custom Typeface on that TextView and add this custom view to the tab.

for (int i = 0; i < tabLayout.getTabCount(); i++) {
//noinspection ConstantConditions
TextView tv=(TextView)LayoutInflater.from(this).inflate(R.layout.custom_tab,null)
tv.setTextColor(customColor)
tabLayout.getTabAt(i).setCustomView(tv);

}

Change tabs text color in TabLayout to different colors programmatically

Try this and let me know if this works for you:

tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
@Override
public void onTabSelected(TabLayout.Tab tab) {
viewPager.setCurrentItem(tab.getPosition());
if (tab.getPosition() == 0) {
tabLayout.getTabAt(0).getIcon().setAlpha(255);
tabLayout.getTabAt(1).getIcon().setAlpha(100);
tabLayout.getTabAt(2).getIcon().setAlpha(100);
} else if (tab.getPosition() == 1) {
tabLayout.getTabAt(0).getIcon().setAlpha(100);
tabLayout.getTabAt(1).getIcon().setAlpha(255);
tabLayout.getTabAt(2).getIcon().setAlpha(100);

} else if (tab.getPosition() == 2) {
tabLayout.getTabAt(0).getIcon().setAlpha(100);
tabLayout.getTabAt(1).getIcon().setAlpha(100);
tabLayout.getTabAt(2).getIcon().setAlpha(255);

}
}

@Surya Prakash Kushawah your way is better.

Changing the color of selected tab

you can do it like this in your tab layout widget

<android.support.design.widget.TabLayout

app:tabBackground="@drawable/selector"

/>

and define your selector.xml in drawable folder

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="@color/tab_selected_color"
android:state_selected="true"/>
<item
android:drawable="@color/tab_unselected_color"
android:state_selected="false"/>
</selector>

How do I change a tab background color when using TabLayout?

What finally worked for me is similar to what @如果我是DJ suggested, but the tabBackground should be in the layout file and not inside the style, so it looks like:

res/layout/somefile.xml:

<android.support.design.widget.TabLayout
....
app:tabBackground="@drawable/tab_color_selector"
...
/>

and the selector
res/drawable/tab_color_selector.xml:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@color/tab_background_selected" android:state_selected="true"/>
<item android:drawable="@color/tab_background_unselected"/>
</selector>

change the selected tab indicator color of TabLayout(android.support.design.widget)

I can't comment so I'll add it here.

Update the Design Support Library and you'll see the setSelectedTabIndicatorColor() method.

This is the line in my build.gradle:

compile 'com.android.support:design:23.1.0'

Change tab indicator color in actionbar

I've always found it easiest to use the tools from the Android Asset Studio, since I'm not particularly graphically inclined. This tool in particular is very relevant to what you're trying to accomplish: http://jgilfelt.github.io/android-actionbarstylegenerator/
. The full suite of tools can be found at http://romannurik.github.io/AndroidAssetStudio/
. Just choose the colors/styles you want, download the zip file, and copy/paste the files into your project. Then in your AndroidManifest.xml file, reference whichever 'Style name' you choose in the generator (the first text box you filled in on the website) in the activity that contains your ActionBar. So for instance if you called your style 'Custom_action_bar' in the generator, you would add it to your activity as follows:

<activity
android:name="com.company.appname.ActivityName"
android:label="@string/somename"
android:theme="@style/Theme.Custom_action_bar">
<!--the above line is all you need to add-->
</activity>


Related Topics



Leave a reply



Submit