androiddrawableimagebuttonlayer-list

Create circle button with custom background image


So I have a background texture (image) that I put on all of my buttons. I want to create a circular button with an icon that retains this background texture.

So far, I have noticed it isn't supported to do this on the shape side:

<shape android:shape="rectangle">
    <solid android:color="@drawable/myTexture" /> <!-- this isn't supported -->
</shape>

Lastly I would otherwise try to use <layer-list>, however as I stated above, I need to still crop the texture to my shape I'm creating.

Is the only way to do this to make my own circular images that combine the background texture and the button icon? This seems a bit excessive, as I would think there should be a programmatic way to accomplish this, but I could be wrong.

Here is an example of what I mean above:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/myTexture" />
    <item>
        <shape android:shape="rectangle">
            <corners android:radius="40dp" />
            <size
                android:height="80dp"
                android:width="80dp" />
            <solid android:color="@color/black" />
        </shape>
    </item>
</layer-list>

In the picture bellow: black is the circle shape, silver is the texture/image (black for contrast)

enter image description here


Solution

  • I haven't solved the programmatic way, but I did end up creating new graphics that combined the icon and the background texture. Using this singular image, I was able to create circular ImageButton's.