Android 按钮的形状不会改变

Android 按钮的形状不会改变,android,android-layout,Android,Android Layout,我找到了一种改变先前回答问题形状的方法 但在应用android:background=“@drawable/x”之后 该属性似乎在布局预览中应用,但在调试之后 有时显示正常背景/无背景 检查了以前的问题没有人能够解决这个问题 可绘制->x.xml-> <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android">

我找到了一种改变先前回答问题形状的方法 但在应用android:background=“@drawable/x”之后 该属性似乎在布局预览中应用,但在调试之后 有时显示正常背景/无背景

检查了以前的问题没有人能够解决这个问题

可绘制->x.xml->

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
            <solid android:color="@android:color/darker_gray" />
            <corners android:bottomLeftRadius="10dp"
                android:bottomRightRadius="10dp"
                android:topLeftRadius="10dp"
                android:topRightRadius="10dp"/>
        </shape>
    </item>
</selector>

布局->

<Button
    android:id="@+id/button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginStart="95dp"
    android:layout_marginTop="140dp"
    android:layout_marginEnd="228dp"
    android:background="@drawable/butt_shape"
    android:text="Button"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

.xml中没有错误消息

角落 Android:raduis:25dp

打开和关闭标签

将所有这些都放在一个形状标签中。

使您的背景(name.xml)类似这样

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <gradient
        android:angle="225"
        android:startColor="#DD2ECCFA"
        android:endColor="@color/loginBackground"/>

    <corners android:bottomRightRadius="8dp"
        android:bottomLeftRadius="8dp"
        android:topRightRadius="8dp"
        android:topLeftRadius="8dp"/>
</shape>

可绘制的父视图是
,这使其成为可绘制的状态列表。你应该移除它。请看unownsp的答案,以确定正确的实现方法。在代码自动创建导致错误的v24 drawable文件夹之前。另外,如果我希望整个按钮具有相同的颜色,请不要使用v24 drawable…使用普通drawable…要创建相同的颜色,请在上面的标记中保持startColor和endColor相同
android:background="@drawable/name"