How do I change the font of TextView on Android?

Asked 2 years ago, Updated 2 years ago, 156 views

I'd like to change android:fontFamily on Android. I've never seen a predefined font on Android, so how do I choose one of the predefined fonts? I don't need to define my font, but I want to change it to a different font.

<TextView
    android:id="@+id/HeaderText"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="52dp"
    android:gravity="center"
    android:text="CallerBlocker"
    android:textSize="40dp"
    android:fontFamily="Arial"
 />

I tried it like the sauce above, but it didn't work. And I've tried android:fontFamily="Arial" but I can't.

android-layout android android-textview typeface

2022-09-22 22:31

1 Answers

On Android 4.1/4.2/5.0, you can use Robot Font.

android:fontFamily="sans-serif" // default robot font
android:fontFamily="sans-serif-light" // Thin robot
android:fontFamily="sans-serif-condensed" // Compressed robot font
android:fontFamily="sans-serif-thin" // thinner robot font (android 4.2)
android:fontFamily="sans-serif-medium" // a slightly thicker robot font (android 5.0)

And it can be combined with textStyle in 14 forms, such as android:textStyle="normal|bold|italic".


2022-09-22 22:31

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.