TabLayout (Android Design Library) Text Color

后端 未结 9 976
面向向阳花
面向向阳花 2020-12-04 22:50

I\'m using the new TabLayout from the Android Design library. I managed to set the textcolor statelist using tabLayout.setTabTextColors(colorstatelist)

How can i ac

9条回答
  •  失恋的感觉
    2020-12-04 23:44

    Via XML attributes:

    
    

    Additionally, there are attributes like tabIndicatorColor or tabIndicatorHeight for further styling.

    In code:

    tabLayout.setTabTextColors(
        getResources().getColor(R.color.your_unselected_text_color),
        getResources().getColor(R.color.your_selected_text_color)
    );
    

    Since this old way is deprecated as of API 23, the alternative is:

    tabLayout.setTabTextColors(
        ContextCompat.getColor(context, R.color.your_unselected_text_color),
        ContextCompat.getColor(context, R.color.your_selected_text_color)
    );
    

提交回复
热议问题