在您指向的 URL 中, button_text.xml 用于设置 textColor 属性。这就是他们在 res/color 文件夹中有 button_text.xml 的原因,因此他们使用了 @color/button_text.xml
但是您正在尝试将其用于背景属性。背景属性在 res/drawable 文件夹中查找某些内容。
检查这个我从互联网上得到了这个选择器自定义按钮。我没有链接。但我感谢海报。它帮助了我。在可绘制文件夹中有这个
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" >
<shape>
<gradient
android:startColor="@color/yellow1"
android:endColor="@color/yellow2"
android:angle="270" />
<stroke
android:width="3dp"
android:color="@color/grey05" />
<corners
android:radius="3dp" />
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp" />
</shape>
</item>
<item android:state_focused="true" >
<shape>
<gradient
android:endColor="@color/orange4"
android:startColor="@color/orange5"
android:angle="270" />
<stroke
android:width="3dp"
android:color="@color/grey05" />
<corners
android:radius="3dp" />
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp" />
</shape>
</item>
<item>
<shape>
<gradient
android:endColor="@color/white1"
android:startColor="@color/white2"
android:angle="270" />
<stroke
android:width="3dp"
android:color="@color/grey05" />
<corners
android:radius="3dp" />
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp" />
</shape>
</item>
</selector>
我在我的 main.xml 布局中使用了这样
<Button android:id="@+id/button1"
android:layout_alignParentLeft="true"
android:layout_marginTop="150dip"
android:layout_marginLeft="45dip"
android:textSize="7pt"
android:layout_height="wrap_content"
android:layout_width="230dip"
android:text="@string/welcomebtntitle1"
android:background="@drawable/custombutton"/>
希望这可以帮助。维克是正确的。
编辑:这是colors.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="yellow1">#F9E60E</color>
<color name="yellow2">#F9F89D</color>
<color name="orange4">#F7BE45</color>
<color name="orange5">#F7D896</color>
<color name="blue2">#19FCDA</color>
<color name="blue25">#D9F7F2</color>
<color name="grey05">#ACA899</color>
<color name="white1">#FFFFFF</color>
<color name="white2">#DDDDDD</color>
</resources>