Forum Xamarin.Android

In Resources/values/styles.xml How to reference to a font located in Assets

aga913aga913 Member ✭✭✭

Hi,
i made a style for tab text appearance and now i'm struggling to reference to a Custom font located in Assets file
after some search i found that in java they have the fonts in the Resources file so they don't have any problem.
but here since we put our fonts in Assets...
direct reference won't work
is there a trick or anyway to solve this ?
i'm a newbie so please go easy on me :)
<style name="MyCustomTabTextAppearance" parent="TextAppearance.Design.Tab"> <item name="android:textSize">12sp</item> <item name="android:textColor">?android:textColorSecondary</item> <item name="textAllCaps">true</item> <item name="android:fontFamily">@Assets/MyFont.ttf</item> </style>
here is a picture if the code is not showing right

Best Answer

  • LeonLuLeonLu Member, Xamarin Team Xamurai
    edited September 2019 Accepted Answer

    First of all, make sure your type of ttf file, if it is AndroidAsset

    Then chanage the style like following format.
    <item name="android:fontFamily">MyFont</item>

    If you want set TextView style, you should change the
    <item name="android:typeface">MyFont</item>

Answers

  • LeonLuLeonLu Member, Xamarin Team Xamurai
    edited September 2019 Accepted Answer

    First of all, make sure your type of ttf file, if it is AndroidAsset

    Then chanage the style like following format.
    <item name="android:fontFamily">MyFont</item>

    If you want set TextView style, you should change the
    <item name="android:typeface">MyFont</item>

  • aga913aga913 Member ✭✭✭

    omg i feel so stupid, i spent 3 days hard mode searching it was just like this....
    thank you VERY MUCH

Sign In or Register to comment.