Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TabLayout.setTabTextColors() not working when trying to change text color

I have a working TabLayout, and I am trying to update the tab text color dynamically, when changing tabs. To do this, I call the setTabTextColors() method on my TabLayout as such:

tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
    @Override
    public void onTabSelected(TabLayout.Tab tab) {
        tabLayout.setTabTextColors(newColorStateList);
    }

    (...)
});

For some reason, the text color doesn't update. Does anyone know how to update the tab text color dynamically?

I am using the Design Support Library v22.2.0.

like image 413
Alexandre Dubois Avatar asked Jul 10 '15 14:07

Alexandre Dubois


1 Answers

TabLayout has a method like this -

setTabTextColors(int normalColor, int selectedColor)

Remember, that int is not color resource value but int parsed from hex

Ex:

tabLayout.setTabTextColors(Color.parseColor("#D3D3D3"),Color.parseColor("#2196f3"))
like image 82
Praveena Avatar answered Oct 02 '22 05:10

Praveena