gpt4 book ai didi

android - 如何在 Android 中更改 TextView 的 fontFamily

转载 作者:IT老高 更新时间:2023-10-28 12:48:33 32 4
gpt4 key购买 nike

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

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

看来我在上面所做的不会真正奏效!顺便说一句 android:fontFamily="Arial" 是一个愚蠢的尝试!

最佳答案

从 android 4.1/4.2/5.0 开始,以下 Roboto字体系列可用:

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)

enter image description here

结合

android:textStyle="normal|bold|italic"

这 16 种变体是可能的:

  • 机器人常规
  • 机器人斜体
  • Roboto 粗体
  • Roboto 粗斜体
  • 机器人灯
  • Roboto-Light 斜体
  • 机器人瘦身
  • Roboto-Thin 斜体
  • 机器人浓缩
  • Roboto-Condensed 斜体
  • Roboto-Condensed 粗体
  • Roboto-Condensed 粗斜体
  • 机器人黑
  • Roboto-黑色斜体
  • 机器人中型
  • Roboto 中斜体

fonts.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="font_family_light">sans-serif-light</string>
<string name="font_family_medium">sans-serif-medium</string>
<string name="font_family_regular">sans-serif</string>
<string name="font_family_condensed">sans-serif-condensed</string>
<string name="font_family_black">sans-serif-black</string>
<string name="font_family_thin">sans-serif-thin</string>
</resources>

关于android - 如何在 Android 中更改 TextView 的 fontFamily,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12128331/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com