3

I would just like to know the best way to achieve this. I have a button that has rounded corners however I would also like to have the background of the button be a texture that is tiled.

I'd appreciate any help

Maurycy
  • 3,911
  • 8
  • 36
  • 44

2 Answers2

1

For rounded corners check this:

http://nishantvnair.wordpress.com/2010/11/09/customize-button-in-android/

to add image background, just add this into dravable resource

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
  <item>
    <shape android:shape="rectangle" android:padding="10dp">
    <corners android:bottomRightRadius="30dp"
             android:bottomLeftRadius="30dp" 
             android:topLeftRadius="30dp"
             android:topRightRadius="30dp" />
    </shape>
  </item>
  <item>
    <bitmap android:src="@drawable/yourfilename" 
            android:tileMode="repeat" />
  </item>
 </layer-list>

from: set Background Image and xml Resource

Community
  • 1
  • 1
hendrix
  • 3,364
  • 8
  • 31
  • 46
  • Thank you, but this doesn't do anything because the rounded shape is drawn first then the square bitmap on top. so it ends up just being a rectangle. – Maurycy Mar 21 '12 at 02:27
1

thank you matej for your suggestions however they do not work :(. I ended up just doing the inevitable and created a custom view where I imported a GradientDrawable from my resources where I defined the rounded corners etc, and then I also imported my "texture" as a BitmapDrawable and used PorterDuffXfermode to mask it. It would be nice to be able to create a shape and then apply a drawable to that shape :(.

Maurycy
  • 3,911
  • 8
  • 36
  • 44