在我的android应用程序中,我想让我的按钮变成绿色和圆角矩形,当有人按下按钮时,它应该将颜色更改为灰色。所以我创建了一个带有选择器的XML文件,并将其赋予圆角矩形的形状,但问题在于当我启动我的应用程序时,默认情况下颜色不是绿色,而是透明。此外,当我按下按钮时,它显示矩形形状,所以我认为shapre也不起作用。这是我的主要颜色:形状和选择器不工作
<color name="colorPrimary">#669900</color>
我custom_button.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent">
<item android:state_focused="true" android:state_pressed="false" android:color="@color/colorPrimary" android:drawable="@color/colorPrimary">
<shape
android:shape="rectangle" android:padding="10dp">
<solid android:color="@color/colorPrimary"/>
<corners
android:bottomRightRadius="15dp"
android:bottomLeftRadius="15dp"
android:topLeftRadius="15dp"
android:topRightRadius="15dp"/>
</shape>
</item>
<item android:state_focused="true" android:state_pressed="true" android:drawable="@drawable/gradient" >
<shape
android:shape="rectangle" android:padding="10dp">
<corners
android:bottomRightRadius="15dp"
android:bottomLeftRadius="15dp"
android:topLeftRadius="15dp"
android:topRightRadius="15dp"/>
</shape>
</item>
<item android:state_focused="false" android:state_pressed="true" android:drawable="@drawable/gradient" >
<shape
android:shape="rectangle" android:padding="10dp">
<corners
android:bottomRightRadius="15dp"
android:bottomLeftRadius="15dp"
android:topLeftRadius="15dp"
android:topRightRadius="15dp"/>
</shape>
</item>
</selector>
而且我已经做了XML文件梯度是gradient.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient android:angle="90"
android:startColor="#880f0f10"
android:centerColor="#880d0d0f"
android:endColor="#885d5d5e"/>
</shape>
</item>
</layer-list>