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

<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"是一个愚蠢的try !

推荐答案

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斜体
  • 机器人黑体
  • 机器人黑体 italic
  • 机器人-灯光
  • 机器人-灯光 italic
  • Roboto-Thin-Thin
  • Roboto-Thin-Thin italic
  • 机器人浓缩
  • 机器人浓缩 italic
  • 机器人浓缩 bold
  • 机器人浓缩 bold italic
  • 机器人-黑色
  • 机器人-黑色 italic
  • Roboto-中型机器人
  • Roboto-中型机器人 italic

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相关问答推荐

在编写中强制软键盘呈现

listOf(listOf(字符串))在lazyArchitect(lazyStream)中合成

如何处理穿戴构图上的长点击事件?

Android开发:主题排版不适用于按钮文本

有人能帮我在应用程序上使用模拟位置时避免被发现吗?我已经反编译并粘贴了一个代码,S小文件

每次重启Android时预填入Room数据库

安卓喷气背包组成倒计时动画

是否可以附加事件处理程序,如onClick,拖动到Canvas Composable中绘制的内容,或使用drawBehind修饰符?

kotlin中&&和and的区别

Android 应用程序从 Android Studio 安装,但不是作为 .apk 在外部安装.抛出java.lang.UnsatisfiedLinkError

在 AGP 8.0 中构建失败,无法应用插件realm-android. APIandroid.registerTransform已删除

了解 Compose 声明性逻辑

在 Jetpack Compose 中使用 .observeAsState() 时,如何在更改 MutableLiveData 的值后开始执行一段代码?

在移动设备上看到时如何增加 PasswordField 文本?

如何将一个 Composable 作为其参数传递给另一个 Composable 并在 Jetpack Compose 中显示/运行它

如何像 XML 一样在 Compose Android Studio 中折叠/展开小部件代码区域/区域

Composable 不会在单击按钮时重新组合

调用时 listFiles() nullpointerexception

如何在 compose 中使用 BottomSheetScaffold 为底页设置半展开高度?

单击登录按钮后从应用程序中退出