[英]change font xamarin.android c#
我想在 Xamarin.Android & visual studio 中更改整个项目的字体,但不幸的是我只能使用字体更改 textview 的字体。 而且这个解决方案还不足以解决我的项目。 有没有办法改变整个程序的字体?
当然,根据现有的问题,我决定将字体添加到项目中名为 font 的文件夹中,并在 style.xml 中定义如下。
<style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:fontFamily">@font/shabnam</item>
<item name="android:typeface">@font/shabnam</item>
</style>
但是在运行程序时,它向我显示了以下错误
未找到资源字体/shabnam(又名 com.companyname.yeti:font/shabnam)。
thank you for your help
您可以为您在 MainActivity 中设置的主题设置字体。
检查 MainActivity 中的主题:
[Activity(Label = "App3", Icon = "@mipmap/icon", Theme = "@style/MainTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize)]
在Resources > values > styles.xml中设置字体
<style name="MainTheme" parent="MainTheme.Base">
<item name="android:fontFamily">@font/amtrash</item>
</style>
font 是我在 Resource 文件夹中创建的文件夹名称,用于放置 font.tff 文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.