Change the icon and title color when you select in the Android TabLayout design library

I am using the TabLayout design library that I want to get

I want to reach

I tried a lot of tutorials, and I can achieve this by setting the tab, but there is a limitation that occurs when choosing a tab. I want to change the color of the text, as well as the image of the icon, which is not possible, referring to any of the lessons that I have read so far. I have tried this so far by adding this to the FragmentStatePagerAdapter

 public View getTabView(int position) { View tab = LayoutInflater.from(mContext).inflate(R.layout.tabbar_view, null); TextView tabText = (TextView) tab.findViewById(R.id.tabText); ImageView tabImage = (ImageView) tab.findViewById(R.id.tabImage); tabText.setText(mFragmentTitles.get(position)); tabImage.setBackgroundResource(mFragmentIcons.get(position)); if (position == 0) { tab.setSelected(true); } return tab; } 
+6
source share
1 answer

The design library has been updated to meet the material specifications for β€œTabs with Icons and Texts,” so you don’t need to set tabs.

But in the current version (23.1.1), only the colors of the text correspond to the specification (the tab is focused - #fff, the tab is not focused - 70% #fff). So you can use the ColorStateList returned by getTabTextColors() to darken the icons with DrawableCompat.setTintList(ColorStateList) .

Try using this gist https://gist.github.com/mikovali/7a89b505cd6306bb94a8 . Removing the string tabs.setTabTextColors(Color.RED, Color.GREEN) should be sufficient to meet the specification for the text and icon in the dark toolbars.

+2
source

All Articles