Skip to content

Instantly share code, notes, and snippets.

@subinkrishna
Last active July 4, 2023 07:49
Show Gist options
  • Save subinkrishna/20d5c373ce46572f901a to your computer and use it in GitHub Desktop.
Save subinkrishna/20d5c373ce46572f901a to your computer and use it in GitHub Desktop.
A simple card background drawable for Android.
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/background_card_selected" android:state_selected="true" />
<item android:drawable="@drawable/background_card_selected" android:state_pressed="true" />
<item android:drawable="@drawable/background_card_default" />
</selector>
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="@color/card_shadow"></solid>
</shape>
</item>
<item android:left="0dp" android:right="0dp" android:bottom="1dp">
<shape android:shape="rectangle">
<solid android:color="@color/card_background_default"></solid>
</shape>
</item>
</layer-list>
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="@color/card_shadow"></solid>
</shape>
</item>
<item android:left="0dp" android:right="0dp" android:bottom="1dp">
<shape android:shape="rectangle">
<solid android:color="@color/card_background_selected"></solid>
</shape>
</item>
</layer-list>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="card_shadow">#8000</color>
<color name="card_background_default">#F6F6F6</color>
<color name="card_background_selected">#CCC</color>
</resources>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment