Home > Mobile >  how to set background AND border at the same time, by selector
how to set background AND border at the same time, by selector

Time:10-10

I want my layout has ALWAYS a border AND, if selected, a different background color. I thought it should work with:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_selected="true">
        <color android:color="@color/selected_color"/>
        <shape android:shape="rectangle">
            <stroke android:width="1dip" android:color="@android:color/black"/>
        </shape>
    </item>
    <item android:state_selected="false">
        <shape android:shape="rectangle">
            <stroke android:width="1dip" android:color="@android:color/black" />
        </shape>
    </item>
</selector>

enter image description here

  • Related