简体   繁体   中英

change font xamarin.android c#

I want to change the font of the whole project in Xamarin.Android & visual studio, but unfortunately I can only change the font of a textview using typeface. And this solution is not enough to solve my project. Is there a solution to change the font of the whole program?

Of course, based on the questions that were available, I decided to add the font in a folder called font in the project and defined it in style.xml as follows.

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

But when running the program, it showed me the following error

resource font/shabnam (aka com.companyname.yeti:font/shabnam) not found.

thank you for your help

You could set the font for the Theme which you set in MainActivity.

Check the Theme in MainActivity:

  [Activity(Label = "App3", Icon = "@mipmap/icon", Theme = "@style/MainTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize)]

Set the font in Resources> values> styles.xml

 <style name="MainTheme" parent="MainTheme.Base">

<item name="android:fontFamily">@font/amtrash</item>
</style>

font is the folder name which i created in Resource folder to put the font.tff file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM