Change Text Size In Tabs.

Hello:

Im facing a little trouble with a TabHost, i want to change the text size on each tab, but i cant find a way to do it, what i have is this:

XML (I Removed The "<" to make it visible)

TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp">
TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
android:background="@drawable/Filter" />
/LinearLayout>
/TabHost>

Tab Activity:

//Set TabHost (OnCreateMethod)
CreateTab(typeof(Tab1), "content1", "DataSet1", Resource.Drawable.Tab1);
CreateTab(typeof(Tab2), "content", "DataSet2", Resource.Drawable.Tab2);
CreateTab(typeof(Tab3), "content", "DataSet3", Resource.Drawable.Tab3);
CreateTab(typeof(Tab4), "content", "DataSet4", Resource.Drawable.Tab4);

//CreateTab Method
var intent = new Intent(this, activityType);
var spec = TabHost.NewTabSpec(tag).SetIndicator(textTab).SetContent(new Intent(this, activityType).AddFlags(Android.Content.ActivityFlags.ClearTop));
var drawableIcon = Resources.GetDrawable(drawableId);
spec.SetIndicator(label, drawableIcon);
spec.SetIndicator (label);
spec.SetContent(intent);
TabHost.AddTab(spec);

How can i set the size for the Label of each tab?

Best Answers

  • KishoreKishore IN
    edited February 2014 Accepted Answer

    Hi @IvanVerges

    Try this,

      for (int j = 0; j < TabWidget.ChildCount; j++) {
            TextView tv = (TextView) TabWidget.GetChildAt (j).FindViewById (Android.Resource.Id.Title);
                tv.SetTextColor(Android.Graphics.Color.ParseColor("#F9F5AD"));
                tv.SetTextSize (Android.Util.ComplexUnitType.Sp,12);
      }
    

    Hope it helps.

  • KishoreKishore IN
    edited February 2014 Accepted Answer

    Hi @IvanVerges

    You could use something like this,

                TabHost.TabChanged += (object sender, TabHost.TabChangeEventArgs e) => {
                    string i = e.TabId; // tag of the tab
                };
    

    if you want to customize tabs altogether follow this post:

    http://forums.xamarin.com/discussion/comment/41768#Comment_41768

    Hope it helps

Answers

  • KishoreKishore INMember
    edited February 2014 Accepted Answer

    Hi @IvanVerges

    Try this,

      for (int j = 0; j < TabWidget.ChildCount; j++) {
            TextView tv = (TextView) TabWidget.GetChildAt (j).FindViewById (Android.Resource.Id.Title);
                tv.SetTextColor(Android.Graphics.Color.ParseColor("#F9F5AD"));
                tv.SetTextSize (Android.Util.ComplexUnitType.Sp,12);
      }
    

    Hope it helps.

  • FraelReinosoFraelReinoso USMember ✭✭

    Thanks You Very Much @Kishore, Very Useful.

  • FraelReinosoFraelReinoso USMember ✭✭

    Another question i have @Kishore:

    Im changing the background color for the tabs inside the loop you showed me, but how can i catch the event when i change the current tab, in order to set a diferent color to the new current tab ?

    This is what i have:

    for (int j = 0; j < TabWidget.ChildCount; j++) {
        TextView tv = (TextView) TabWidget.GetChildAt (j).FindViewById(Android.Resource.Id.Title);
        tv.SetTextColor(Android.Graphics.Color.ParseColor("#FFFFFF"));
        tv.SetTextSize (Android.Util.ComplexUnitType.Sp, 50);
        TabWidget.GetChildAt (j).SetBackgroundColor (Android.Graphics.Color.ParseColor("#4B97AB")); //Unselected Tab
    }
    TabWidget.GetChildAt (TabHost.CurrentTab).SetBackgroundColor (Android.Graphics.Color.ParseColor("#000000"));    //Selected Color
    
  • KishoreKishore INMember
    edited February 2014 Accepted Answer

    Hi @IvanVerges

    You could use something like this,

                TabHost.TabChanged += (object sender, TabHost.TabChangeEventArgs e) => {
                    string i = e.TabId; // tag of the tab
                };
    

    if you want to customize tabs altogether follow this post:

    http://forums.xamarin.com/discussion/comment/41768#Comment_41768

    Hope it helps

  • FraelReinosoFraelReinoso USMember ✭✭

    Thanks again @Kishore, very useful information.

Sign In or Register to comment.