Change icon and title color when selected in android design library TabLayout

前端 未结 1 1053
清歌不尽
清歌不尽 2021-01-05 11:52

I am using TabLayout of design library what i want to acheive is

I have tried many tutorial and i am able to achieve it by customizing the tab

相关标签:
1条回答
  • 2021-01-05 12:20

    The Design Library were updated to match the material design "Tabs with icons and text" specs, so you don't need a custom tab view.

    But in the current version (23.1.1), only the text colors match the spec (tab focused - #fff, tab unfocused - 70% #fff). So you can use the ColorStateList returned by getTabTextColors() to tint the icons using DrawableCompat.setTintList(ColorStateList).

    Try to use this gist https://gist.github.com/mikovali/7a89b505cd6306bb94a8. Removing the line tabs.setTabTextColors(Color.RED, Color.GREEN) should be enough to match the spec for both text and icon on dark toolbars.

    0 讨论(0)
提交回复
热议问题