[英]Custom Fonts in Xamarin.Forms NavigationBar + ActionBar
您好,我想知道如何在Xamarin的导航栏中使用自定义字体。
在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>
我的问题是我在文档中找不到有关“字体家族”或“标签”之类的东西。
我的印象是我可能必须使用Custom渲染,但是我无法弄清楚为样式化导航栏而必须替换的Class。 有人有想法吗?
在iOS上似乎有一种简单直接的方法,但除非在两个平台上都能做到,否则我不想在其中进行样式设置。 跨平台的Xamarin.Forms方式是理想的选择,但任何可行的方法都可以。
像教程这其中谈论的自定义字体似乎完全忽略了Android动作条。
通常,可以在App.xaml中全局设置自定义字体。 显然,这些设置不会影响工具栏。
但是,对于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>
然后在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.