0

How can I create shape with state in Kotlin(or java) for example I want create below shape with Kotlin(or java)

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:state_pressed="true">
    <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
        <corners android:radius="999dp" />
        <stroke android:width="6dp" android:color="#bfbfbf" />
        <solid android:color="#f44336" />
    </shape>
</item>

<item android:state_pressed="true">
    <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
        <corners android:radius="999dp" />
        <stroke android:width="2dip" android:color="#E0E0E0" />
        <solid android:color="#f44336" />
    </shape>
</item>

<item android:state_checked="true">
    <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
        <corners android:radius="999dp" />
        <stroke android:width="2dip" android:color="#E0E0E0" />
        <solid android:color="#f44336" />
    </shape>
</item>

<item>
    <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
        <corners android:radius="999dp" />
        <stroke android:width="6dp" android:color="#bfbfbf" />
        <solid android:color="#f44336" />
    </shape>
</item>

I see this link1 and link2 but i wonder how to create state to drawable

Aniruddh Parihar
  • 2,674
  • 2
  • 19
  • 34
peyman
  • 133
  • 9

0 Answers0