Tuesday, February 23, 2021

Android How to set custom Font for entire application

In the styles.xml, define a custom style 


     <style name="CustomTextViewStyle" parent="android:Widget.TextView">

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

     </style>


now inside the fonts folder, create a fonts.xml file and define the below


 <?xml version="1.0" encoding="utf-8"?>

 <font-family xmlns:android="http://schemas.android.com/apk/res/android">

   <font

        android:fontStyle="normal"

        android:fontWeight="400"

        android:font="@font/montserrat" />

    <font

        android:fontStyle="normal"

        android:fontWeight="700"

        android:font="@font/montserrat_bold" />

 </font-family>


and place the font files in the fonts folder itself. 


references:

https://stackoverflow.com/questions/2711858/is-it-possible-to-set-a-custom-font-for-entire-of-application

No comments:

Post a Comment