MaterialButton app:icon 属性未呈现

MaterialButton app:icon attribute isn't rendering

我想将按钮添加到我的 xml 文件中。

<com.google.android.material.button.MaterialButton 
        android:id="@+id/submitButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        style="@style/Widget.AppCompat.Button.Borderless"
        app:icon="@drawable/doorkey"
        android:text="@string/sign_up"
        app:iconTint="@null"
        android:layout_marginTop="20dp"
        android:textSize="20sp"
        android:textColor="@color/x"
        app:layout_constraintTop_toBottomOf="@id/first_input_layout1"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        android:layout_marginHorizontal="100dp"
        app:layout_constraintBottom_toBottomOf="parent"
        />

如您所见,我在按钮中添加了一个图标。但由于某种原因,它没有出现在设计界面中。对于样式,我尝试根据文档添加 style="@style/Widget.MaterialComponents.Button.Icon" 。但是我遇到了“渲染问题”

"Failed to find '@attr/textAppearanceButton' in current theme."

然后我改成了style="@style/Widget.AppCompat.Button.Borderless"。我曾尝试更改 material 设计的依赖版本,但没有成功。你能帮帮我吗?

您的应用主题应继承自 MaterialComponents 主题之一。检查您的 AndroidManifest 文件以查看应用主题的路径,然后为其设置正确的父主题。您还可以查看文档 here