笔触属性不适用于android studio中的按钮

问题描述

这是我的Buttons.xml文件

    <?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
    <corners android:radius="50dp"/>
    <gradient android:startColor="#8E8816"
        android:endColor="#145038"
        android:angle="270" />
    <stroke android:color="#680D0D" android:width="5dp"/>

</shape>

这是我的activity_main.xml 我试图将android:background更改为android:src,但是它也无法正常工作

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/teal_700"
    tools:context=".MainActivity">

    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/buttons"
        android:text="Button" />
</RelativeLayout>

只有corners属性可以正常工作

不仅笔触而且背景没有变化 我没弄错我在哪里...有人可以帮我吗

此处将背景应用为android:background =“ @ drawable / buttons” 后的按钮外观 Button_image

解决方法

发生这种情况是因为,如果您使用Button主题和MaterialButton tints the background的默认样式,而MaterialComponents会自动被MaterialButton替换colorPrimary

您必须使用:

<Button
    android:background="@drawable/buttons"
    app:backgroundTint="@null"
    ... />

enter image description here