1

I don't want to customise my fonts.I just want to use the fonts available in android studio.How do i change the font of my text to sans or serif or monospace?

3 Answers3

1

-Hello as per this Stackoverflow answer

-android:typeface is used in xml for changing the fonts.

-You final code would be:-

<Textview .......... =android:typeface="normal/sans/monospace"..../>
Community
  • 1
  • 1
Hardy
  • 2,541
  • 22
  • 44
0

First download the .ttf file of the font you need (arial.ttf). Place it in the assets folder(Inside assest folder create new folder named "fonts" and place it inside it). If "txtyour" is the textvies you want to apply the font , use the following piece of code,

 Typeface type = Typeface.createFromAsset(getAssets(),"fonts/arial.ttf"); 
 txtview.setTypeface(type);
Tufan
  • 3,384
  • 4
  • 32
  • 53
0

If you want to change the font for the whole app then I will recommend to use the styles for this.

Just add the following line to your styles.xml file -

<style name="AppTheme" parent="AppBaseTheme">
    <item name="android:textViewStyle">@style/TextAppearance.Sans</item>
    <item name="android:buttonStyle">@style/TextAppearance.Sans</item>
</style>

<style name="TextAppearance.Sans" parent="TextAppearance.AppCompat.Large">
        <item name="android:fontFamily">sans-serif-light</item>
        <item name="android:textStyle">normal</item>
</style>

If you don't want to change the font through out the app then instead of setting in AppTheme just simply define the style element in each TextView you want to change the font for -

<TextView
    style="@style/TextAppearance.Sans"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"/>
Varundroid
  • 8,940
  • 14
  • 62
  • 91