I have created the action bar by
ActionBar actionbar = getActionBar()
The background of the action bar is changed by
actionbar.setBackgroundDrawable(actionBarBackgroundImage);
Now I need to change the action bar tabs underline color programmatically. Is there any method to change the action bar tabs underline color?
you can use this code:
actionBar.setStackedBackgroundDrawable(new ColorDrawable(yourColor));
Refer this, for customize action bar,
Here is a much easier way. I know you were looking for a programmatic change, but this one is REALLY easy.
I've been struggling with this for days, but finally found the solution. I'm using AppCompat. You can set
colorAccent
in your theme and that will change the highlight color on your ActionBar. Like so:Here it is in context:
Where I originally posted this answer: Android Tab underline color not changing
Alternatively you could use Android Action Bar Style Generator to easily theme your action bar and tabs.
I'll suggest you use ActionBarSherlock. There is one sample available in the library named "Style ActionBar". (this is only way you can change ActionBar tabs underline color)
if you have customized ActionBar then You have to add this style in ActionBar Style
or here is way how to Do this
create style like below (here i have used ActionBarShareLock if you don't want to use then use android-support-v4.jar for support all Android OS Version)
actionbar_tab_bg.xml
applay this style in your activity in android manifest file
for more detail check this answer and this article.
EDITED : 29-09-2015
ActionBarSherlock is deprecated so alternatively you can use android
design
support library and android appappcompat
library for TOOLBAR(Action-Bar is deprecated so..) and TABS.use
TabLayout
like belowhere is sample of android design support library with tab
I tried many of the suggestions posted here and other places with no luck. But I think I managed to piece together a (albeit not perfect) solution.
The TabWidget is using a selector. Essentially it is showing a different 9 patch image depending on the state of the tab (selected, pressed, etc.). I finally figured out that you could generate a selector programmatically. I started with generated 9 patches from http://android-holo-colors.com/ (color: #727272, TabWidget: Yes).
The biggest issue was setting the color. Setting the color filter did nothing. So, I ended up changing the colors of each of the pixels of the 9 patch image inside a loop.
Example of usage: