1

enter image description here

Please suggest someone how to create button like this with xml style in android, without using any image only with the help of color ,shape and style.

4

2 回答 2

4

Use layer-list for this.Try the below code

<Button
        android:id="@+id/button_register"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/button_background"
        android:text="Cancel"
        android:padding="15dp"
        android:textStyle="bold"
         />

button_background.xml

    <?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

    <item>
        <shape android:shape="rectangle" >

    <gradient
        android:endColor="#FFFFFF"
        android:startColor="#A9A9A9"
        android:type="linear" />


            <stroke
                android:width="2dp"
                android:color="#5E2612" />


            <corners
                android:bottomLeftRadius="10dp"
                android:bottomRightRadius="10dp"
                android:topLeftRadius="10dp"
                android:topRightRadius="10dp" />
        </shape>
    </item>
    <item
        android:bottom="4dp"
        android:left="4dp"
        android:right="4dp"
        android:top="4dp">
        <shape android:shape="rectangle" >
            <gradient
                android:angle="90"
                android:endColor="#A9A9A9"
                android:startColor="#FFFFFF"
                android:type="linear" />

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


        </shape>
    </item>

</layer-list>

It should work

image

于 2013-10-08T12:48:47.273 回答
3

Check out these examples how to create custum buttons. Link1 Link2

于 2013-10-08T12:36:16.187 回答