0

I have an appCompactActivity with icon tabs. The tabs are part of a TabLayout. I want that the selected tab icon will get whiter.

Edit:

I want to do it programmatically

How can i do that?

Montoya
  • 2,819
  • 3
  • 37
  • 65

1 Answers1

2

You might have to create a selector for your icon on yout tablayout.

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/icon_pressed"
      android:state_pressed="true" />
<item android:drawable="@drawable/icon_selected"
      android:state_selected="true" />
<item android:drawable="@drawable/icon_normal" />

Save this xml in your drawable folder and use it with R.drawable.myicon

LordCommanDev
  • 922
  • 12
  • 38
  • Also you can check this link http://stackoverflow.com/questions/30828951/tab-with-icon-using-tablayout-in-android-design-library – LordCommanDev Nov 13 '15 at 21:53
  • Is there a way to do that programmatically? – Montoya Nov 13 '15 at 21:58
  • There is another way, I suppose that in your onTabSelected method, you might have to add your icon when is selected and in your onTabUnselected your icon when is unselected but as far I read is better to use a drawable. – LordCommanDev Nov 13 '15 at 22:07
  • the icons seems to be a little grayer then the original drawable. A selector won't work here because the icon is fully white and i can't change him to a whiter one. – Montoya Nov 13 '15 at 22:36