Search code examples
androidstrokelayer-list

Layer-list item stroke acts as solid


I have a layer-list:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
    <shape
        android:shape="oval"
        >
        <size android:height="50dp" android:width="50dp"/>
        <solid android:color="@android:color/background_light"/>
        </shape>
</item>
<item>
    <shape android:shape="oval">
        <size android:width="50dp" android:height="50dp"/>
        <stroke android:width="1dp" android:color="@android:color/black"/>
    </shape>
</item>
</layer-list>

On 4.2.2 and above it creates a white circle with a black border.

Below 4.2.2 it creates a black circle.

Is there any way to get it working below 4.2.2? Am I missing something?

My goal would be to get it work from api14.


Solution

  • Well eventually I found my own answer:

    the trick is, you don't create a new item for the border, you add it to the solid shape, and it work's from api14. Like this:

    <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
     <item>
      <shape android:shape="oval">
        <size android:height="50dp" android:width="50dp"/>
        <solid android:color="@android:color/background_light"/>
        <stroke android:width="1dp" android:color="@android:color/black"/>
      </shape>
    </item>
    

    actually in this case you don't even need a layer-list, but I have some other shapes in there, so that's why I'm using it. This way you can change the background color, and it still has a nice border to it.