0

m new to Android Application development.

I'm trying to apply Color to Button in my Android Application.

I have tried below link.

Standard Android Button with a different color

I have created CustomButton.xml and color.xml

below is my button 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" />

but still I'm not able to see any color on my button.enter image description here

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>
Community
  • 1
  • 1
Manish
  • 1,246
  • 3
  • 14
  • 26
  • 1
    Show @drawable/customButton... – ElDuderino Jun 10 '14 at 15:13
  • Make sure colors blue2 and blue25 are defined somewhere in a block. You might try simplifying things and building up to what you currently have so you can see what change stops the color from working correctly. – Gravitoid Jun 10 '14 at 16:55

2 Answers2

0

Take care, "CustomButton" is diferent to "customButton". First, check this: try to click on "@drawable/customButton" holding Ctrl key. It must open your custom XML file.

iflorit
  • 740
  • 5
  • 10
0

Just use this tool to create button for custom color and shape. Its easy to customize according to your wish.

Chandru
  • 5,954
  • 11
  • 45
  • 85