[英]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.