简体   繁体   English

Xamarin.Forms NavigationBar + ActionBar中的自定义字体

[英]Custom Fonts in Xamarin.Forms NavigationBar + ActionBar

Hello I would like to know how to use custom fonts in the navigation bar in Xamarin. 您好,我想知道如何在Xamarin的导航栏中使用自定义字体。

In Xaml it is possible to do set navigation bar properties like this: 在Xaml中,可以这样设置导航栏属性:

<Style TargetType="NavigationPage">
        <Setter Property="BarBackgroundColor" Value="Pink"/>
        <Setter Property="XXX">
          <Setter.Value>
            <OnPlatform x:TypeArguments="x:String"
              iOS="Kenyan Coffee" Android="kenyan coffee rg.ttf#Kenyan Coffee Rg"
              WinPhone=""/>
          </Setter.Value>

        </Setter>
</Style>

My problem is I can't find anything in the documentation about a "Font family" or "label" or something like that. 我的问题是我在文档中找不到有关“字体家族”或“标签”之类的东西。

I get the impression that I might have to use a Custom rendered but I cannot figure out what Class I would have to replace in order to style the navigation bar. 我的印象是我可能必须使用Custom渲染,但是我无法弄清楚为样式化导航栏而必须替换的Class。 Does anybody have any Ideas? 有人有想法吗?

There seems to be a simple straight forward way to do it for iOS but I don't want to style it There unless I can do it on both platforms. 在iOS上似乎有一种简单直接的方法,但除非在两个平台上都能做到,否则我不想在其中进行样式设置。 A crossplatform Xamarin.Forms way would be ideal but anything that works would be fine. 跨平台的Xamarin.Forms方式是理想的选择,但任何可行的方法都可以。

Tutorials like this which talk about custom fonts seem to ignore the android actionBar completely. 像教程其中谈论的自定义字体似乎完全忽略了Android动作条。

Custom font in general can be set in App.xaml globally. 通常,可以在App.xaml中全局设置自定义字体。 Apparently those settings don't affect toolbar. 显然,这些设置不会影响工具栏。

However, for Android's toolbar, you have to make add a style in Android's style.xml . 但是,对于Android的工具栏,您必须在Android的style.xml中添加样式。

<style name="Toolbar.TitleText" parent="TextAppearance.Widget.AppCompat.Toolbar.Title">
    <!--set your custom font properties-->
    <item name="android:textSize">18sp</item>
</style>

then just reference it in Toolbar.xaml : 然后在Toolbar.xaml中引用它:

<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:minHeight="?attr/actionBarSize"
    android:background="@color/primary"
    android:theme="@style/MainTheme"
    android:popupTheme="@style/ThemeOverlay.AppCompat.Light"
    app:titleTextAppearance="@style/Toolbar.TitleText" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM