将颜色应用于Android按钮

将颜色应用于Android按钮,android,xml,Android,Xml,我是Android应用程序开发新手 我正在尝试在我的Android应用程序中对按钮应用颜色 我试过下面的链接 我已经创建了CustomButton.xml和color.xml 下面是我的按钮xml <Button android:id="@+id/ButtonReachedOffice" android:layout_width="wrap_content" android:layout_height="wrap_content"

我是Android应用程序开发新手

我正在尝试在我的Android应用程序中对按钮应用颜色

我试过下面的链接

我已经创建了CustomButton.xml和color.xml

下面是我的按钮xml

<Button
        android:id="@+id/ButtonReachedOffice"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="102dp"
        android:layout_marginTop="98dp"
        android:text="Reached Office"
        android:background="@drawable/customButton" />

但我还是看不到我按钮上的任何颜色

customButton.xml

<?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/blue2"
                android:startColor="@color/blue25"
                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>


小心,“CustomButton”与“CustomButton”不同。首先,选中此项:尝试按住Ctrl键单击“@drawable/customButton”。它必须打开您的自定义XML文件。

只需使用该工具为自定义颜色和形状创建按钮。它很容易根据您的愿望定制

显示@drawable/customButton…确保在块中的某个位置定义了蓝色2和蓝色25。您可以尝试将事情简化并建立到您当前拥有的内容,这样您就可以看到哪些更改会阻止颜色正常工作。