Xamarin.Forms NavigationBar + ActionBar中的自定义字体 [英] Custom Fonts in Xamarin.Forms NavigationBar + ActionBar

查看:175
本文介绍了Xamarin.Forms NavigationBar + ActionBar中的自定义字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我想知道如何在Xamarin的导航栏中使用自定义字体.

Hello I would like to know how to use custom fonts in the navigation bar in Xamarin.

在Xaml中,可以这样设置导航栏属性:

In Xaml it is possible to do set navigation bar properties like this:

<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.

我的印象是我可能必须使用Custom渲染,但是我无法弄清楚为样式化导航栏而必须替换的Class.有人有任何想法吗?

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. Does anybody have any Ideas?

在iOS上似乎有一种简单直接的方法,但是除非在两个平台上都能做到,否则我不想在其中进行样式设置.跨平台的Xamarin.Forms方式是理想的选择,但任何可行的方法都可以.

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. A crossplatform Xamarin.Forms way would be ideal but anything that works would be fine.

类似于谈论自定义字体的="nofollow noreferrer">此似乎完全忽略了android actionBar.

Tutorials like this which talk about custom fonts seem to ignore the android actionBar completely.

推荐答案

通常可以在App.xaml中全局设置自定义字体.显然,这些设置不会影响工具栏.

Custom font in general can be set in App.xaml globally. Apparently those settings don't affect toolbar.

但是,对于Android的工具栏,您必须在Android的style.xml中添加样式.

However, for Android's toolbar, you have to make add a style in Android's style.xml .

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

然后只需在Toolbar.xaml中引用它即可:

then just reference it in 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" />

这篇关于Xamarin.Forms NavigationBar + ActionBar中的自定义字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆