1

Is there any way to create a XML drawable with drawable and stroke?

Usually we use shape with stroke like this code:

        <item android:state_pressed="true">
        <shape>
            <gradient
                android:angle="270.0"
                android:endColor="@color/rounded_container_bg"
                android:startColor="@color/rounded_container_bg" />

            <corners android:radius="11.0dip" />
        </shape>
    </item>
    <item>
        <shape>
            <stroke
                android:width="1.0px"
                android:color="@color/rounded_container_border" />

I think this is not possible to use drawable in this code But is there any other methods that I can use it to create an image surrounded by stroke?

I need this method to create buttons and I want to use a background image (PNG) with stroke.

Thanks

user3051834
  • 261
  • 1
  • 4
  • 13

2 Answers2

1

Use LayerDrawable (called Layer-List in xml)

LayerDrawable programmatically

You can mix shapes from xml with drawable that are drawn in code and bitmaps and use it as single Drawable.

Community
  • 1
  • 1
Yaroslav Mytkalyk
  • 16,950
  • 10
  • 72
  • 99
0

you can use ImageButton instead of normal button

<ImageButton
    android:background="your_drawable_shape"
    android:src="your_image"
/>

or you can use LayerDrawable

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/stroke_drawable"/>
    <item android:drawable="@drawable/your_image" />
</layer-list>
Orhan Obut
  • 8,756
  • 5
  • 32
  • 42