Default font size of the text displayed in the navigation bar

hecate 1 Reputation point
2021-04-09T22:21:19.433+00:00

I am attempting to reproduce the navigation bar to customize certain aspects of it and need to know the default font size pertaining to the text displayed on it (similar to this question involving the default height of the navigation bar).

Developer technologies .NET Xamarin
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. JessieZhang-MSFT 7,716 Reputation points Microsoft External Staff
    2021-04-12T10:08:03.073+00:00

    Hello,

    Welcome to our Microsoft Q&A platform!

    I am attempting to reproduce the navigation bar to customize certain aspects of it and need to know the default font size pertaining to the text displayed on it

    If you want to change the font for the header of a Navigation page, you can use Custom Renderer to achieve this .

    You can refer to the following code:

    In Android

    [assembly: ExportRenderer(typeof(CustomNavigationPage), typeof(CustomNavigationPageRenderer))]  
    namespace CustomFontsNavigationPage.Droid.Renderers  
    {  
    public class CustomNavigationPageRenderer : NavigationPageRenderer  
    {  
        private Android.Support.V7.Widget.Toolbar _toolbar;  
      
        public override void OnViewAdded(Android.Views.View child)  
        {  
            base.OnViewAdded(child);  
      
            if (child.GetType() == typeof(Android.Support.V7.Widget.Toolbar))  
            {  
                _toolbar = (Android.Support.V7.Widget.Toolbar)child;  
                _toolbar.ChildViewAdded += Toolbar_ChildViewAdded;  
            }  
        }  
      
        protected override void Dispose(bool disposing)  
        {  
            base.Dispose(disposing);  
      
            if(disposing)  
            {  
                _toolbar.ChildViewAdded -= Toolbar_ChildViewAdded;  
            }  
        }  
      
        private void Toolbar_ChildViewAdded(object sender, ChildViewAddedEventArgs e)  
        {  
            var view = e.Child.GetType();  
      
            if (e.Child.GetType() == typeof(Android.Widget.TextView))  
            {  
                var textView = (Android.Widget.TextView)e.Child;  
                var spaceFont = Typeface.CreateFromAsset(Forms.Context.ApplicationContext.Assets, "Trashtalk.ttf");  
                var systemFont = Typeface.DEFAULT;  
                var systemBoldFont = Typeface.DEFAULT_BOLD;  
                textView.Typeface = spaceFont;  
                _toolbar.ChildViewAdded -= Toolbar_ChildViewAdded;  
            }  
        }  
    }  
    }  
    

    In IOS

    [assembly: ExportRenderer(typeof(CustomNavigationPage), typeof(CustomNavigationPageRenderer))]  
    namespace CustomFontsNavigationPage.iOS.Renderers  
    {  
    public class CustomNavigationPageRenderer : NavigationRenderer  
    {  
        protected override void OnElementChanged(VisualElementChangedEventArgs e)  
        {  
            base.OnElementChanged(e);  
      
            if (e.NewElement != null)  
            {  
                var att = new UITextAttributes();  
                UIFont customFont = UIFont.FromName("Trashtalk", 20);  
                UIFont systemFont = UIFont.SystemFontOfSize(20.0);  
                UIFont systemBoldFont = UIFont.SystemFontOfSize(20.0 , FontAttributes.Bold);  
                att.Font = font;  
                UINavigationBar.Appearance.SetTitleTextAttributes(att);  
            }  
        }  
    }  
    }  
    

    Refer : this sample.

    Best Regards,

    Jessie Zhang

    ---
    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.