Changing ActionBar tabs underline color programmatically
Alternatively you could use Android Action Bar Style Generator to easily theme your action bar and tabs.
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:
<item name="colorAccent">@color/highlightcolor</item>
Here it is in context:
<style name="LightTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">@color/darkgrey</item>
<item name="colorPrimaryDark">@color/black</item>
<item name="colorAccent">@color/highlightcolor</item>
</style>
Where I originally posted this answer: Android Tab underline color not changing
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)
<style name="Theme.AndroidDevelopers" parent="Theme.Sherlock.Light">
<item name="android:actionBarTabStyle">@style/MyActionBarTabStyle</item>
<item name="actionBarTabStyle">@style/MyActionBarTabStyle</item>
</style>
<!-- style for the tabs -->
<style name="MyActionBarTabStyle" parent="Widget.Sherlock.Light.ActionBar.TabBar">
<item name="android:background">@drawable/actionbar_tab_bg</item>
<item name="android:paddingLeft">32dp</item>
<item name="android:paddingRight">32dp</item>
actionbar_tab_bg.xml
<item android:state_focused="false" android:state_selected="false" android:state_pressed="false" android:drawable="@drawable/ad_tab_unselected_holo" />
<item android:state_focused="false" android:state_selected="true" android:state_pressed="false" android:drawable="@drawable/ad_tab_selected_holo" />
<item android:state_selected="false" android:state_pressed="true" android:drawable="@drawable/ad_tab_selected_pressed_holo" />
<item android:state_selected="true" android:state_pressed="true" android:drawable="@drawable/ad_tab_selected_pressed_holo" />
applay this style in your activity in android manifest file
<activity
android:name="com.example.tabstyle.MainActivity"
android:label="@string/app_name"
android:theme="@style/Theme.AndroidDevelopers" >
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 app appcompat
library for TOOLBAR(Action-Bar is deprecated so..) and TABS.
use TabLayout
like below
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabGravity="center"
app:tabMode="scrollable"
app:tabSelectedTextColor="@color/white"
app:tabIndicatorColor="@color/colorPrimary"
app:tabIndicatorHeight="2dip"
app:tabTextAppearance="?android:attr/textAppearanceMedium"
app:tabTextColor="@color/colorAccent" />
here is sample of android design support library with tab