Reputation: 1187
How do you set the color of the tab host indicator color I want to change the light blue default color to lets says RED.
And I need to this programatically as I am making the tabs programatically.
I did some research and looked at this example but it does not work for me. With the progamtic approach.
TabWidget current tab bottom line color
Thanks
Upvotes: 1
Views: 2734
Reputation: 55340
You can do this programmatically, even change the color as you want, by following the solution in the linked question you mention, plus adding a ColorFilter
to adjust the color.
So:
tab_indicator_ab_example.xml
(in drawable) plus the 6 associated png files (tab_*.png) for each drawable density.TabWidget
child views to set their background, however:Instead of this code:
for(int i = 0; i < widget.getChildCount(); i++) {
... /* same as before */
v.setBackgroundResource(R.drawable.your_tab_selector_drawable);
}
write something like this:
for(int i = 0; i < widget.getChildCount(); i++) {
... /* same as before */
Drawable d = getResources().getDrawable(R.drawable.tab_indicator_ab_example);
d.setColorFilter(Color.GREEN, PorterDuff.Mode.SRC_IN);
v.setBackgroundDrawable(d);
}
Upvotes: 1