You can change it through the tabs title TextView
. For details see:
Android: Change Tab Text Color Programmatically
Example usage for you having a text color of red would be:
import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.Color;
import android.os.Bundle;
import android.widget.TabHost;
import android.widget.TextView;
import com.example.myproject.R;
public class HealthyEating extends TabActivity {
Resources res;
TabHost tabHost;
Intent intent;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_healthy_eating);
res = getResources();
tabHost = getTabHost();
TabHost.TabSpec spec;
intent = new Intent().setClass(this, BreakfastRecipe.class);
spec = tabHost.newTabSpec("Breakfast Recipes").setIndicator("Breakfast Recipes")
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, LunchRecipe.class);
spec = tabHost.newTabSpec("Lunch Recipes").setIndicator("Lunch Recipes")
.setContent(intent);
tabHost.addTab(spec);
tabHost.setCurrentTab(0);
int titleColor = Color.RED; //<-- change this to the color you want the title text to be
for(int i = 0;i < tabHost.getTabWidget().getChildCount(); i++)
{
TextView textView = (TextView)tabHost.getTabWidget().getChildAt(i).findViewById(android.R.id.title);
textView.setTextColor(titleColor);
}
}
}
The for
loop goes through each of the tabs that you've added to the TabHost
and accesses the TextView
that is associated with the title label. The setTextColor
method is used to change the text color to what you want (in this example red). It may be worthwhile checking out the docs for TabWidget.
Note in particular the extra import statements that you will need: import android.widget.TextView
and import android.graphics.Color
This example worked for me with the following activity_healthy_eating
file:
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@android:id/tabhost">
<LinearLayout
android:id="@+id/LinearLayout01"
android:orientation="vertical"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
<TabWidget
android:id="@android:id/tabs"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_marginBottom="5dip">
</TabWidget>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
</FrameLayout>
</LinearLayout>
</TabHost>
If you're getting any errors please post them and I'll try to address them.
More information on Color
(docs) in Android can be found here
An online tool for finding the hex color code you're after can found here.