Search code examples
androidandroid-layoutandroid-intentandroid-tabhost

How to increase the Font size of a Tab title


I have a Vision tab with vision icon etc..,I want to increase the Font Size ,any one help?

Here My Code:

TabSpec vision = tabHost.newTabSpec("Vision");
        vision.setIndicator("Vision",
                getResources().getDrawable(R.drawable.visionicon));

Solution

  • For setting custom Layout for your Tabs :

    First design a layout for the image & text to be passed named "tabs_bg":

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/tabsLayout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="center"
    android:orientation="vertical" >
    
    <ImageView
        android:id="@+id/tabs_image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal"
        android:scaleType="fitXY" />
    
    <TextView
        android:id="@+id/tabs_tv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal" />
    </LinearLayout>
    

    Next you need to add this method in your TabActivity :

    /***** Method for Custom Tabs *****/
    private static View createTabView(final Context context, final Drawable image, final String text) {
        View tab_view = LayoutInflater.from(context).inflate(R.layout.tabs_bg, null);
        ImageView img = (ImageView) tab_view.findViewById(R.id.tabs_image);
        img.setImageDrawable(image);
        TextView txt_text = (TextView) tab_view.findViewById(R.id.tabs_tv);
        txt_badge.setText(text);
        return tab_view;
    }
    

    Next in your TabActivity you need to Setup Your Tabs by using this code :

     TabHost.addTab(TabHost.newTabSpec("Tab1").setIndicator(createTabView(TabHost.getContext(),
                getResources().getDrawable(R.drawable.tab1_image), "Tab_Name")), Tab1.class, null);