I want to change tab indicator color in android. Default color for tab host in android app is blue. I want to change to some other color. Please help me.
My code is as follows:
`
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="-4dp"
android:layout_weight="0" />
<View
android:layout_width="fill_parent"
android:background="@color/btn_color"
android:layout_height="5dp"/>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1" />
<Button
android:id="@+id/buttonBookConfirm"
android:layout_width="fill_parent"
android:layout_height="35dp"
android:textColor="@color/btn_text"
android:background="@color/btn_color"
android:layout_alignParentBottom="true"
android:text="@string/btn_text" />
</LinearLayout>
`
My java code is as follows: ` public class TabHostActivity extends TabActivity { /** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tab_host);
Resources res = getResources(); // Resource object to get Drawables
TabHost tabHost = getTabHost(); // The activity TabHost
TabHost.TabSpec spec; // Reusable TabSpec for each tab
Intent intent; // Reusable Intent for each tab
// Create an Intent to launch an Activity for the tab (to be reused)
intent = new Intent().setClass(TabHostActivity.this,HomeActivity.class);
spec = tabHost.newTabSpec("home")
.setIndicator("", res.getDrawable(R.drawable.plays))
.setContent(intent);
tabHost.addTab(spec);
// Do the same for the other tabs
intent = new Intent().setClass(TabHostActivity.this, AboutActivity.class);
spec = tabHost.newTabSpec("about")
.setIndicator("", res.getDrawable(R.drawable.movies))
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(TabHostActivity.this, ContactActivity.class);
spec = tabHost
.newTabSpec("contact")
.setIndicator("",
res.getDrawable(R.drawable.events))
.setContent(intent);
tabHost.addTab(spec);
//set tab which one you want open first time 0 or 1 or 2
tabHost.setCurrentTab(0);
}`
I have attach image for the same. I just want to change blue color line present below selected tab.
android:setLeftStripDrawable="@color/your_custom_color
create a custom color resources in res->values folder and refernce this to there