【问题标题】:Setting font to recyclerview item text has a delay将字体设置为 recyclerview 项目文本有延迟
【发布时间】:2020-05-20 17:38:38
【问题描述】:

我在我的风格中使用font-family,如下所示:

<?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"
    xmlns:tools="http://schemas.android.com/tools"
    tools:ignore="UnusedAttribute">
    <font
        app:font="@font/montserrat_regular"
        app:fontWeight="400"
        android:font="@font/montserrat_regular"
        android:fontWeight="400" />
    <font
        app:font="@font/montserrat_bold"
        app:fontWeight="700"
        android:font="@font/montserrat_bold"
        android:fontWeight="700"/>
</font-family>

在主题中:

        <!-- font family -->
        <item name="android:fontFamily">@font/mobile_font</item>
        <item name="fontFamily">@font/mobile_font</item>

这是我的布局:

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools">

    <data>

        <variable
            name="model"
            type="main.dashboard.UserContactItem" />
    </data>

    <RelativeLayout
        android:layout_width="@dimen/material_size_96"
        android:layout_height="wrap_content">

        <androidx.appcompat.widget.AppCompatTextView
            android:id="@+id/tvName"
            style="@style/Caption"
            asyncText="@{model.title}"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/ivProfile"
            android:layout_marginTop="@dimen/material_size_8"
            android:gravity="center"
            android:textColor="?android:attr/textColorPrimary"/>

    </RelativeLayout>
</layout>

当项目出现在应用程序的屏幕上时,首先,textview 以 Android 的默认字体显示,然后一秒钟后,字体设置为 textview。 有什么问题?

【问题讨论】:

    标签: android styles material-design


    【解决方案1】:

    经过大量调查,我发现问题出在 textAppearance 设置为 textview 和 style="@style/Caption"

        <style name="Caption" parent="TextAppearance.MaterialComponents.Caption">
            <item name="android:textSize">@dimen/text_size_smaller</item>
            <item name="android:textAllCaps">false</item>
            <item name="android:textStyle">normal</item>
            <item name="android:letterSpacing">0</item>
        </style>
    

    parent="TextAppearance.MaterialComponents.Caption" 继承是问题所在。所以删除它解决了我的问题!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-05-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-06
      相关资源
      最近更新 更多