本文介绍了如何在Android中更改TextView的fontFamily的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我想在 Android 中更改 android:fontFamily 但我在 Android 中没有看到任何预定义的字体.我如何选择其中一个预定义的?我真的不需要定义我自己的 TypeFace,但我所需要的只是与它现在显示的不同.

看来我在那里做的真的行不通!顺便说一句 android:fontFamily="Arial" 是一次愚蠢的尝试!

解决方案

来自 android 4.1/4.2/5.0,以下

结合

android:textStyle="normal|bold|italic"

这 16 个变体是可能的:

  • Roboto 常规
  • Roboto 斜体
  • Roboto 粗体
  • Roboto 粗斜体
  • Roboto-Light
  • Roboto-Light 斜体
  • Roboto-Thin
  • Roboto-细斜体
  • Roboto-Condensed
  • Roboto 浓缩斜体
  • Roboto-Condensed 粗体
  • Roboto-Condensed 粗斜体
  • 机器人黑
  • Roboto-Black 斜体
  • Roboto-Medium
  • Roboto-中斜体

fonts.

So I'd like to change the android:fontFamily in Android but I don't see any pre-defined fonts in Android. How do I select one of the pre-defined ones? I don't really need to define my own TypeFace but all I need is something different from what it shows right now.

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

It seems what I did up there won't really work! BTW android:fontFamily="Arial" was a stupid attempt!

解决方案

From android 4.1 / 4.2 / 5.0, the following Roboto font families are available:

android:fontFamily="sans-serif"           // roboto regular
android:fontFamily="sans-serif-light"     // roboto light
android:fontFamily="sans-serif-condensed" // roboto condensed
android:fontFamily="sans-serif-black"     // roboto black
android:fontFamily="sans-serif-thin"      // roboto thin (android 4.2)
android:fontFamily="sans-serif-medium"    // roboto medium (android 5.0)

in combination with

android:textStyle="normal|bold|italic"

this 16 variants are possible:

  • Roboto regular
  • Roboto italic
  • Roboto bold
  • Roboto bold italic
  • Roboto-Light
  • Roboto-Light italic
  • Roboto-Thin
  • Roboto-Thin italic
  • Roboto-Condensed
  • Roboto-Condensed italic
  • Roboto-Condensed bold
  • Roboto-Condensed bold italic
  • Roboto-Black
  • Roboto-Black italic
  • Roboto-Medium
  • Roboto-Medium italic

fonts.

<?

这篇关于如何在Android中更改TextView的fontFamily的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-07 23:33