I use new TabLayout
from com.android.support:design
library. I want to change background of the selected/unselected tabs.
I look at sources and found only tabBackground
attribute that change all tabs colour and does not control selected tab colour.
How can I control selected/unselected tab background?
If you look into the
TabLayout.class
you will notice innerTabView.class
for tab's actual layout. It's same layout as any other withisSelected
attribute. Selecting tab will also have impact on this so all you need to do is to create selector background drawable likeand attach it to the tabBackground attribute e.g. in XML like
Define:
Apply:
I met this problem too. I just searched
tabIndicatorColor
in the whole project and found the following code in someR.java
:So the problem is solved. May this will be some help for you.
i.e. I use IDEA
I read How to Style ActionBar, tab background on selected tab and figure out what to do. It is really similar problem, but I found awesome solution specially for
TabLayout
:note that
layout_height
andtabIndicatorHeight
have the same height. So you get pretty transition animation with this way.