Shwetabh Singh
Shwetabh Singh

Reputation: 197

How to change the color of text in tabs of tabbed activity?

     TabLayout tabLayout = (TabLayout) findViewById(R.id.tab_layout);

    tabLayout.addTab(tabLayout.newTab().setText("Videos"));

    tabLayout.addTab(tabLayout.newTab().setText("Games"));

    tabLayout.addTab(tabLayout.newTab().setText("Music"));

Videos,games and music is coming in white.

With my current theme, it's coming (text in tab bar)white in color.I want to retain my theme and just want to change the color of text from white to any other color.

Upvotes: 0

Views: 140

Answers (2)

Rakshit Nawani
Rakshit Nawani

Reputation: 2604

Try this

    TabLayout tabLayout = (TabLayout) findViewById(R.id.tab_layout);

    tabLayout.addTab(tabLayout.newTab().setText("Videos"));
    tabLayout.addTab(tabLayout.newTab().setText("Games"));
    tabLayout.addTab(tabLayout.newTab().setText("Music"));

tabLayout.setTabTextColors(Color.parseColor("#ffffff"), Color.parseColor("#000000"));

Upvotes: 2

2D3D
2D3D

Reputation: 353

<style name="MyCustomTabLayout" parent="Widget.Design.TabLayout">
    <item name="tabTextAppearance">@style/MyCustomTabText</item>
    <item name="tabSelectedTextColor">@color/tab_text_act</item>
</style>

<style name="MyCustomTabText" parent="TextAppearance.AppCompat.Button">
    <item name="android:textSize">14sp</item>
    <item name="android:textColor">@color/tab_text</item>
</style>

This should allow you to change the color of the text to whatever you want

Upvotes: 0

Related Questions