vanomart vanomart - 3 months ago 21
Android Question

Different selector behavior on API 21 and API 23

What kind of sorcery is this?

Api 23:
Api 23

Api 21:
Api 21

I am trying to implement a custom checkbox selector. After a couple of hours of trying to figure out what is wrong with my code, I came to the conclusion that the selector is rendered differently on different api levels. The images above are from AS, but I experienced the same behavior on a real device.

Here is the code if you want to test it out:

<item
android:state_checked="false">
<layer-list>
<item>
<shape android:innerRadiusRatio="5"
android:shape="ring"
android:thickness="0dp"
android:useLevel="false">
<solid
android:width="1dp"
android:color="#08aa92"/>
</shape>
</item>
<item>
<shape android:innerRadiusRatio="2"
android:shape="ring"
android:thickness="0dp"
android:useLevel="false">
<stroke
android:width="2dp"
android:color="#cccccc"/>
</shape>
</item>
</layer-list>
</item>


My question is: How can I fix this?

edit 1: it's seems like it's related to ring shapes for L preview not working , but I didn't manage to make it work yet.

Answer

Ok, I still don't know what's the problem with API 23, but I managed to fix this problem by changing the first selector item to:

        <item>
            <shape android:innerRadiusRatio="1000"
                   android:shape="ring"
                   android:thickness="10dp"
                   android:useLevel="false">
                <solid android:width="1dp" 
                       android:color="#08aa92"/>
            </shape>
        </item>

Only the thickness and android:innerRadiusRatio changed.

Comments