Sunday, March 2, 2014

How to create custom Button in Android

How to create custom Button in Android

                                              


STEP 01
               create a xml file in drawable-hdip folder and insert this code ,here in call it as zcustomer button
                             <selector xmlns:android="http://schemas.android.com/apk/res/android">
 <item android:state_pressed="true" >
  <shape>
  <solid
   android:color="#ef4444" />
  <stroke
   android:width="1dp"
   android:color="#FFFFFF" />
  <corners
   android:radius="3dp" />
  <padding
   android:left="10dp"
   android:top="10dp"
   android:right="10dp"
   android:bottom="10dp" />
  </shape>
 </item>
  <item>
  <shape>
  <gradient
   android:startColor="#ef4444"
   android:endColor="#992f2f"
   android:angle="270" />
  <stroke
   android:width="1dp"
   android:color="#FFFFFF" />
  <corners
   android:radius="3dp" />
  <padding
   android:left="10dp"
   android:top="10dp"
   android:right="10dp"
   android:bottom="10dp" />
 </shape>
 </item>
</selector>



STEP 02
              Add this cord for values->style.xml

   <style name="CustomStyleButton" parent="@android:style/Widget.Button">
     <item name="android:textSize">16sp</item>
     <item name="android:textStyle">bold</item>
     <item name="android:textColor">#dedfdc</item>
     <item name="android:gravity">center</item>
     <item name="android:shadowColor">#000000</item>
     <item name="android:shadowDx">1</item>
    <item name="android:shadowDy">1</item>
     <item name="android:shadowRadius">0.6</item>
     <item  name="android:background">@drawable/zcustomerbutton</item>
     <item name="android:padding">10dip</item>
    </style>



                                                      @drawable/zcustomerbutton is the name of the xml file i created on my drawable folder 
change the color values on your own using hex color values in http://www.color-hex.com/   
STEP 03      
              call the style in button     [add this cord of the xml button]
style="@style/CustomStyleButton"
  use the name that you given in the style.xml page 

No comments:

Post a Comment