How to Set a Custom Font Family in the Xamarin ActionBar Title?

Jakubee

As in title. I found the idea how to do this here Custom Fonts in Xamarin.Forms NavigationBar + ActionBar that tells to define this in style.xml file but I'm not able to get the custom font family.

So my style look like this right now:

 <style name="Toolbar.TitleText" parent="TextAppearance.Widget.AppCompat.Toolbar.Title">
<!--set your custom font properties-->
<item name="android:textSize">18sp</item>
<item name="android:fontFamily">HelveticaNeue Medium.ttf</item>
<item name="android:textColor">@android:color/white</item>

Sparsha Bhattarai

You can create a custom renderer in android for this purpose. The renderer simply changes the typeface of your navigation bar using the resource defined in your android project. You can use the following renderer in android:

[assembly: ExportRenderer(typeof(NavigationPage), typeof(AndroidNavigationRenderer))]
namespace Xamarin.Droid.DependencyServices
{
  public class AndroidNavigationRenderer : 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;
        }
    }

    private void Toolbar_ChildViewAdded(object sender, ChildViewAddedEventArgs e)
    {
        var view = e.Child.GetType();
        if (e.Child.GetType() == typeof(Android.Support.V7.Widget.AppCompatTextView))
        {
            var textView = (Android.Support.V7.Widget.AppCompatTextView)e.Child;
            textView.Typeface = Typeface.CreateFromAsset(this.Context.Assets, "fonts/QuicksandRegular.ttf");

            toolbar.ChildViewAdded -= Toolbar_ChildViewAdded;
        }
    }
  }
}

For UWP, you can define a custom style in your app.xaml to override the default style of your title bar. You can use the following code in UWP:

 <Style x:Key="TitleTextBlockStyle" TargetType="TextBlock">
    <Setter Property="FontSize" Value="18"/>
    <Setter Property="FontStyle" Value="Normal"/>
    <Setter Property="FontWeight" Value="SemiBold"/>
    <Setter Property="FontFamily" Value="Assets/Fonts/QuicksandRegular.ttf#Quicksand"/>
    <Setter Property="Padding" Value="10"/>
 </Style>

Simply change the font family to the font family of your choice.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to Set a Custom Font in the ActionBar Title?

how to set default font family available in android to action bar title

How to set a custom font to the title in toolbar android

How to set column colors, title colors , font size , font family in external css file for highcharts?

How to create custom font family with bold font

How to set custom font and weight (style) to UInavigationbar title

How to change actionbar title color in Xamarin android

How to set font family but retain fallback stack?

How to set default font family in React Native?

How to set the font family I want in css?

How to dynamically change a custom ActionBar title?

Set Android Custom Font on Tab Title

How to change the font family of matplotlib legend AND legend title?

Change custom actionbar title

How to change font family of label in Xamarin.Forms

How do you apply a custom font family for placeholder, textbox & button?

How to set a custom view in actionbar in android?

How to set custom ActionBar color / style?

custom fonts with Font-Family

How to set the font size of navigation bar title

how to set font for a tab title in jtabbedpane

How to set custom font for backBarButtonItem

how to set specific font family for each locale in jetpack compose

How to set the font-family as specified when editing post in wordpress?

How to set default font family for entire Android app

how to set the UIFont family and name with display font on the UITableView?

How to set a font family to an entire Word document in Apache POI XWPF

How to set the font-family like a digital clock CSS?

How to set a global/default font-family without universal selectors?