Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the font size of tabhost in android

How can the font size of the tabs be changed? I extend TabActivity for the tabs.

like image 508
ReNa Avatar asked Apr 26 '11 10:04

ReNa


People also ask

What is the default text size in Android Studio?

The body text size in Material Design is 14sp. You should think of this as the normal font size, and basically everything else a variation on it. For instance, while 14sp is the default text size when the text can be quite long, when there's only a small modal with a bit of text, it's 16sp!


3 Answers

You can define themes, use styles to achieve this:

First you create the theme (name:CustomTheme) for your Activity in your res/values/styles.xml:

<style name="CustomTheme" parent="@android:style/Theme">     <item name="android:tabWidgetStyle">@style/CustomTabWidget</item> </style> <style name="CustomTabWidget" parent="@android:style/Widget.TabWidget">     <item name="android:textAppearance">@style/CustomTabWidgetText</item> </style> <style name="CustomTabWidgetText"      parent="@android:style/TextAppearance.Widget.TabWidget">     <item name="android:textSize">20sp</item>     <item name="android:textStyle">bold</item> </style> 

Then in your androidManifest.xml you specify the theme above for your TabActivity or Activity containing your TabWidget:

<activity android:name="MyTabActivity" android:theme="@style/CustomTheme"> 

This will serve you with the output you want (of course you should change the size and style for your preference).

like image 120
rekaszeru Avatar answered Oct 04 '22 15:10

rekaszeru


Its not pretty but try this Dirty Fix :

TabWidget tw = (TabWidget)tabHost.findViewById(android.R.id.tabs);
View tabView = tw.getChildTabViewAt(0);
TextView tv = (TextView)tabView.findViewById(android.R.id.title);
tv.setTextSize(20);

or

 //Do this to hack font size of title text
 LinearLayout ll = (LinearLayout) tabHost.getChildAt(0);
 TabWidget tw = (TabWidget) ll.getChildAt(0);

 // for changing the text size of first tab
 RelativeLayout rllf = (RelativeLayout) tw.getChildAt(0);
 TextView lf = (TextView) rllf.getChildAt(1);
 lf.setTextSize(21);
 lf.setPadding(0, 0, 0, 6);
like image 22
Kartik Domadiya Avatar answered Oct 04 '22 16:10

Kartik Domadiya


Slightly generalized:

final TabWidget tw = (TabWidget)mTabHost.findViewById(android.R.id.tabs);
    for (int i = 0; i < tw.getChildCount(); ++i)
    {
        final View tabView = tw.getChildTabViewAt(i);
        final TextView tv = (TextView)tabView.findViewById(android.R.id.title);
        tv.setTextSize(20);
    }
like image 30
Martin.Martinsson Avatar answered Oct 04 '22 17:10

Martin.Martinsson