0

I want to put the text on the every tab of my application and also want to change its color from default. . . How it is Possible ?

richq
  • 55,548
  • 20
  • 150
  • 144
  • Would please you stop tagging your questions android-ndk, it is very annoying. They have *nothing* to do with the NDK. – richq Apr 21 '11 at 10:40

3 Answers3

2

I have defined a custom style for tab in my one of the application.

Which is something like:

(Note: define this style inside the styles.xml file)

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <style name="MyTheme" parent="@android:style/Theme.Light">
        <item name="android:tabWidgetStyle">@style/LightTabWidget</item>
    </style>

    <style name="LightTabWidget" parent="@android:style/Widget.TabWidget">
        <!-- set textColor to red, so you can verify that it applied. -->
        <!-- <item name="android:textColor">#f00</item>  -->
        <item name="android:textSize">12px</item>
        <item name="android:textColor">#1E90FF</item>
    </style>

</resources>

and give this theme in the application tag inside AndroidManifest.xml file as:

 <application android:icon="@drawable/icon" 
                 android:label="@string/app_name"
                 android:theme="@style/MyTheme">

Update:

Still you are already done with solutions for the problem, let me suggest an example which is also valid: how to change the color of the tabs indicator text in android?

Community
  • 1
  • 1
Paresh Mayani
  • 127,700
  • 71
  • 241
  • 295
  • where i hv put the styles.xml file. . . ?? –  Apr 21 '11 at 10:17
  • @Shreyash its inside the Values folder. – Paresh Mayani Apr 21 '11 at 10:19
  • @Shreyash check my updated answer, and put this code inside styles.xml inside the values folder. – Paresh Mayani Apr 21 '11 at 10:24
  • Now the file has no error but there is no any effect on My current Tab text. . . What should be problem ? –  Apr 21 '11 at 10:37
  • @Shreyash glad to have your response quickly. But after having problem, what you have done to have solution? – Paresh Mayani Apr 21 '11 at 10:44
  • Sorry, I was just checking the View. . . as i lost the Default view.. I got the Tabview Background as Black in normal and while it is selected it will shown gray colour. . . Before it will shown White while selected and gray in normal view. . . –  Apr 21 '11 at 11:11
1

Something like that:

private View createTabIndicator(String text) {
    Button button = new Button(this);
    button.setBackgroundResource(R.drawable.tab);
    button.setText(text);
    button.setTextColor(Color.WHITE);
    button.setGravity(Gravity.CENTER);
    return button;
}
...
getTabHost().addTab(getTabHost().newTabSpec("name").setIndicator(createTabIndicator("name")).setContent(data));
Flavio
  • 6,205
  • 4
  • 30
  • 28
0

Here is an example of doing this,

TabSpec pecHome = tabHost.newTabSpec("Home").setIndicator("Home",
                res.getDrawable(R.drawable.home)).setContent(intentHome);
tabHost.addTab(specHome);

here ssetIndicator will enable you to display the text.

Thats all Best Reagrds Anup

Anup Rojekar
  • 1,093
  • 9
  • 29
  • Thanks, but i want to change the colout of it. . . I want to change the colour of the Indicator. . –  Apr 21 '11 at 09:44
  • I think this will help you tabhost.getTabWidget().getChildAt(i).setBackgroundColor(Color.parseColor("#FF0000")); //unselected – Anup Rojekar Apr 21 '11 at 09:49
  • Will u please give me Some More detail code. . as i didnt get u proper. . . –  Apr 21 '11 at 09:56
  • is "getTabWidget()" a ready made method ? or Custom Function ? –  Apr 21 '11 at 09:57