gpt4 book ai didi

android - 天文台字体在android中没有改变

转载 作者:行者123 更新时间:2023-12-05 00:13:46 24 4
gpt4 key购买 nike

我想在 android 中更改计时器的字体。我已将默认字体设置为自定义字体。除了天文钟外,该字体似乎适用于所有地方。我也尝试过设置 android:fontFamily="@font/myfont" 但它没有用。虽然字体似乎在预览窗口中应用,但当我在我的设备上运行我的应用程序时它并没有改变。

有克服它的想法吗?

这是我的代码:

<Chronometer
android:fontFamily="@font/linotte_semibold"
android:id="@+id/audio_player_chronometer"
android:layout_width="wrap_content"
android:layout_height="20dp"
android:layout_below="@+id/frame_layout"
android:textColor="@color/white"
android:layout_margin="5dp"
/>

最佳答案

您可以从 Google Material 下载字体

  1. 转到布局编辑器
  2. 选择您的view并在右侧查看All Attributes并找到fontFamily

fontFamily Attribute with default font

  1. 现在点击向下箭头,它会打开一个选择字体的窗口

Resources of Google Fonts

  1. 找到你想要的字体,你也可以搜索并点击ok

  2. 您的Chronometer 看起来会有所不同

Preview of changed font

这是代码

<Chronometer
android:id="@+id/chronometer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:fontFamily="@font/allan_bold"
android:textColor="@color/colorAccent"
android:textSize="30sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

如果字体没有改变,请在您的 Activity.class

中使用它
Chronometer chronometer = findViewById(R.id.chronometer);

chronometer.setTypeface(ResourcesCompat.getFont(this, R.font.allan_bold));
//replace allan_bold with your desired font

编辑 1这是设备中的输出 Device output

希望这会有所帮助!

关于android - 天文台字体在android中没有改变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59039369/

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