I want to create rounded buttons in an Android program. I have looked at How to create EditText with rounded corners?
What I want to achieve is:
- Rounded Edge Buttons
- Change Button background/appearance on different states (Like Onclick, Focus)
- Use my own PNG for the background and not create a shape.
You can do a rounded corner button without resorting to an ImageView.
A background selector resource,
button_background.xml:For each state, a drawable resource, e.g. button_press.xml:
Note the
cornerselement, this gets you rounded corners!Then set the background drawable on the button:
EDIT (9/2018): The same technique can be used to create a circular button. A circle is really just a square button with radius size set to 1/2 the side of the square
Additionally, in the example above the
strokeandgradientaren’t necessary elements, they are just examples and ways that you’ll be able to see the rounded corner shape