0

I am trying to make custom button below is the code. I want to achieve gradient,corners,shadow in my button and also I want to put small Icon in the center of the button say lock button

 <Button
        android:id="@+id/button5"
        android:layout_width="150dp"
        android:layout_height="150dp"
        android:layout_alignBaseline="@+id/button4"
        android:layout_alignBottom="@+id/button4"
        android:layout_marginLeft="15dp"
        android:layout_toRightOf="@+id/button1"
        android:shadowColor="#000000"
        android:shadowRadius="50"
        android:background="@drawable/levelselectionbutton"/>

I achieved gradient and corners and also image at some extend but I want it in center and if i use gravity then image is getting zoomed nd also looking blur. what should i do to achieve it in the center whitout getting pixalized here is the code of my layerlist

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

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

  <corners  android:radius="20dp"  />
  <gradient 
       android:startColor="#7F7F7F"
       android:type="linear" 
       android:endColor="#FFFF"
       android:angle="270"/>

   </shape>  
</item>
<item
    android:drawable="@drawable/ic_hh_lock"
    android:gravity="center"
 />

How will I achieve the shadow one more item in the list?

user1169079
  • 3,053
  • 5
  • 42
  • 71
  • This Is how I do it [http://stackoverflow.com/a/11579459/672773][1] [1]: http://stackoverflow.com/a/11579459/672773 Hope this can help you – João M Mar 11 '13 at 15:14

1 Answers1

1

Try to wrap your image in a bitmap xml like this:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
   <item>
      <shape android:shape="rectangle" >
         <corners  android:radius="20dp"  />
         <gradient 
           android:startColor="#7F7F7F"
           android:type="linear" 
           android:endColor="#FFFF"
           android:angle="270"/>
      </shape>  
   </item>
   <item>
      <bitmap 
          android:src="@drawable/ic_hh_lock"
          android:gravity="center" />
   </item>
</layer-list>
user
  • 86,916
  • 18
  • 197
  • 190
  • and what abt the shadow part ? how do i achieve it ? – user1169079 Feb 17 '12 at 10:50
  • @user1201239 Shadow on which element, the button, the image from the layer-list? – user Feb 17 '12 at 10:56
  • @user1201239 In xml you can't create the shadow. In your layer-list you could try to add another bigger shape(with a few pixels) and fill it with gray/black but visual isn't that good, not a true shadow. – user Feb 17 '12 at 12:06