Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 89864

Change TextSize of TabbarTitle in Android Programmatically

$
0
0

I know there are lot's of samples of doing this but none of them works for me. I can change the colors, even the Text of a Tabbar Title but not the the size nor font. I tried through Custom TabbedPageRenderer. And I have a simple Demo project with a ExtendedTabbedPageRenderer.cs in the Android part.
The Application class is a FormsAppCompatActivity.

` protected override void OnVisibilityChanged(Android.Views.View changedView, [GeneratedEnum] ViewStates visibility)
{
base.OnVisibilityChanged(changedView, visibility);

        if (visibility == ViewStates.Visible)
        {
            TabLayout tabs = changedView.FindViewById<TabLayout>(Droid.Resource.Id.sliding_tabs);

            // Changing Colors is working
            tabs.SetBackgroundColor(Android.Graphics.Color.Tomato);
            tabs.SetTabTextColors(Android.Graphics.Color.Blue, Android.Graphics.Color.Red);
            tabs.SetSelectedTabIndicatorColor(Android.Graphics.Color.Black);

            ViewGroup vg = (ViewGroup)tabs.GetChildAt(0);
            int tabsCount = vg.ChildCount;
            for (int j = 0; j < tabsCount; j++)
            {
                ViewGroup vgTab = (ViewGroup)vg.GetChildAt(j);

                int tabChildsCount = vgTab.ChildCount;
                for (int i = 0; i < tabChildsCount; i++)
                {
                    Android.Views.View tabViewChild = vgTab.GetChildAt(i);
                    if (tabViewChild is Android.Widget.TextView)
                    {
                        // This is working
                        ((Android.Widget.TextView)tabViewChild).Text = "TEST";

                        // This is all not working
                        ((Android.Widget.TextView)tabViewChild).SetTextSize(Android.Util.ComplexUnitType.Dip, 80.0f);
                        ((Android.Widget.TextView)tabViewChild).SetTextAppearance(Android.Resource.Style.TextAppearanceDeviceDefaultSmall);

                        Font f = Font.OfSize("sans-serif", 8);
                        Typeface tf = FontExtensions.ToTypeface(f);
                        ((Android.Widget.TextView)tabViewChild).SetTypeface(tf, Android.Graphics.TypefaceStyle.Normal);

                    }
                }
            }
        }
    }`

Viewing all articles
Browse latest Browse all 89864

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>