2

So, I need to create three different buttons which look almost the same: all of them have rounded corners but different background colors. What I did is to have three different shapes created and give them a particular color. Although this approach gets the job done, I think there's gotta be a better and less cumbersome way to do this.

I've found a workaround to this by changing the background dynamically, but I was wondering whether there's an easier way to have this done without having to write any Java code.

This is the code for all three of the drawables:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <corners
        android:radius="4dp"/>
    <padding
        android:bottom="15dp"
        android:top="15dp"
        android:left="15dp"
        android:right="15dp" />
    <solid
        android:color="@color/green" />
</shape>

Is there any way to use "some kind of inheritance" to extend the code above to have three different "children" of this shape by only adding / overriding some of the parent's properties?

Thanks in advance!

Community
  • 1
  • 1
fed
  • 51
  • 4

0 Answers0