计时码表字体在android中不变 [英] Chronometer font doesn't change in android
本文介绍了计时码表字体在android中不变的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在android中更改天文钟的字体.我将默认字体设置为自定义字体.该字体似乎适用于除天文钟以外的所有位置.我也尝试过设置 android:fontFamily ="@ font/myfont"
,但这没有用.虽然该字体似乎是在预览窗口中应用的,但是当我在设备上运行我的应用程序时,字体并没有改变.
I want to change the font of my chronometer in android.I have set my default font to be a custom font . The font seems to be applied every where except the chronometer. I have also tried setting android:fontFamily="@font/myfont"
but it didn't work. Though the font appears to be applied in the preview window, but it doesn't change when i run my app on my device.
有什么办法克服它吗?
这是我的代码:
<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材料中下载字体
You can download Fonts from Google Material
- 转到布局编辑器
- 选择您的
视图
并在右侧查看所有属性
并找到fontFamily
- Go to layout editor
- Select your
view
and viewAll Attributes
on your right side and findfontFamily
- 现在单击
向下箭头
,它将打开一个用于选择字体的窗口
- Now click
down arrow
, it will open a window for selecting 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 这是设备中的输出
希望这会有所帮助!
这篇关于计时码表字体在android中不变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文