0

I want to add a custom image as android button background with shaping it in rounded rectangle. I am trying as following.

This is my xml file that I am setting as background to button.

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/btn">
<shape android:shape="rectangle">
    <corners android:radius="30dp"/>
</shape>
</item>

I want the "btn" image as background of the button and I want the shape of button as rounded rectangle. But as I set the image, the shape is remaining in full rectangular format same as that of image. Please suggest any necessary improvements.

Thank you.

  • Possible duplicate of [How to make the corners of a button round?](http://stackoverflow.com/questions/6054562/how-to-make-the-corners-of-a-button-round) – Neji Mar 21 '17 at 14:08

1 Answers1

0

You can't use a drawable background and round its corners like that.

You could do this programmatically, by extending Button, drawing the drawable as a bitmap on the Canvas of your subclass and then erasing it using certain shapes, but it sounds as an overkill.

I would just make the btn drawable rounded, it seems way easier.

Community
  • 1
  • 1
Jorge Martín
  • 268
  • 3
  • 13