【问题标题】:Xamarin.Forms change Default FontFamily in all AppXamarin.Forms 更改所有 App 中的 Default FontFamily
【发布时间】:2020-10-26 10:11:50
【问题描述】:
我添加了自定义字体:
[assembly: ExportFont("Roboto-Regular.ttf", Alias ="Roboto")]
同样在App.xaml:
<Style TargetType="Label">
<Setter Property="FontFamily" Value="Roboto"/>
</Style>
并且还可以添加用于Entry等...
但是可以通过一行代码更改在您创建项目时初始化的默认字体系列?如果可以怎么办?
【问题讨论】:
标签:
c#
xamarin.forms
font-family
【解决方案1】:
您需要为标签、条目、选择器等创建控件。使用默认字体系列。我已经为你创建了一个标签控件
public class MyFontLabel : Label
{
public MyFontLabel()
{
Style = Application.Current.Resources["FontLabelStyle"] as Style;
}
}
app.xaml 中的样式
<Style x:Key="FontLabelStyle" TargetType="Label">
<Setter Property="FontFamily" Value="Roboto"/>
</Style>
始终使用它
<local:MyFontLabel Text="My Text"/>