How to change color of tab when its selected, see below screen shot:
i am showing Orange color in ActionBar, in a same way i wanna show orange color in place of ligh
put this function and call it to yout Activity and pass tabhost as a parameter
public static void setTabColor(TabHost tabhost) {
for (int i = 0; i < tabhost.getTabWidget().getChildCount(); i++) {
tabhost.getTabWidget().getChildAt(i)
.setBackgroundResource(R.drawable.header_blank); // unselected
}
tabhost.getTabWidget().setCurrentTab(0);
tabhost.getTabWidget().getChildAt(tabhost.getCurrentTab())
.setBackgroundResource(R.drawable.tab_selected_new); // selected
// //have
// to
// change
}
call this as following way
setTabColor(tabHost);
tabHost.setOnTabChangedListener(new OnTabChangeListener() {
@Override
public void onTabChanged(String arg0) {
setTabColor(tabHost);
}
});
hope this is useful to you
you can use like this
tab_background_select.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true"
android:drawable="@drawable/tab_background" />// for selected
<item android:drawable="@drawable/tab" /> // for normal
</selector>
use this code in order to change the color of selected tab:-
tabLayout.setTabTextColors(Color.parseColor("color_for_unselected_tab"), Color.parseColor("color_for_tab"));
for tab-indicator
tabLayout.setSelectedTabIndicatorColor(Color.parseColor("#627179")));
you can use this code and set the background of your item_tab xml file
tab_selection.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true" android:state_pressed="false"
android:drawable="@drawable/tab_bg_selected" />
<item android:state_selected="false" android:state_pressed="false"
android:drawable="@drawable/tab_bg_unselected" />
<item android:state_pressed="true"
android:drawable="@drawable/tab_bg_pressed" />
</selector>