添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

安卓 textFontWeight api级别小于28级

3 人关注

我有一个textView的样式资源

<style name="AppText.Note.Medium">
    <item name="android:textFontWeight" tools:targetApi="p">500</item>
</style>

但它在API级别28或更高的水平上工作。有什么办法可以在API级别23上使用它吗?或者也许有一些替代方案?

1 个评论
android
android-styles
DanMan
DanMan
发布于 2020-04-22
2 个回答
Dinesh
Dinesh
发布于 2022-11-10
已采纳
0 人赞同

支持字体家族在API低于26的情况下使用

  <item name="fontWeight">500</item>
    
属性fontWeight只在API级别26及以上的情况下使用(当前最小值为21)。
@FreePhoenix Use app:fontWeight="500" instead of android:fontWeight="500"
@Dinesh 当你设置的时候没有任何变化,只有 android:textFontWeight 有效果,但这是针对API 28+的。
Abhijith mogaveera
Abhijith mogaveera
发布于 2022-11-10
0 人赞同

这在所有api层面上都有效

<?xml version="1.0" encoding="utf-8"?>
<font-family xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">
        app:font="@font/sdfglay_bold"
        app:fontWeight="700"/>
        app:font="@font/sdfglay_light"
        app:fontWeight="300"/>
        app:font="@font/sdfglay_regular"
        app:fontWeight="400"/>
        app:font="@font/sdfglay_medium"
        app:fontWeight="500"/>
        app:font="@font/sdfglay_semibold"
        app:fontWeight="600"/>

而不是这个字体家族

<com.google.android.material.textview.MaterialTextView
        android:id="@+id/postDesc"
        android:layout_width="0dp"
        android:fontFamily="@font/sdfglay_light"
        android:layout_height="wrap_content"
        android:layout_marginRight="90dp"
        android:ellipsize="end"