Search code examples
androidandroid-actionbarandroid-tabs

Android - Change ActionBar tab underline color programatically


I need to change the underline color of the ActionBar tabs programmatically. I've checked around SO and found nothing; I've looked at this question, but none of the answers helped.

I know how to change the color in styles.xml like so:

<style name="ActionBarTabStyle" parent="@android:style/Widget.Holo.ActionBar.TabView">
    <item name="android:background">@color/red</item>
</style>

enter image description here

I know how to change the background color, but I need to change the color of the white line below Tab 1.

I need to change this color while the app is running, using Java code. Is there any way to do this?


Solution

  • there are two ways you can do this

    you can get action bar instance and call actionbar.setBackgroundDrawable with this you can change background color of the action bar else define two different custom themes in app and change the theme programatically.