3

I have the following drawable:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle">
            <solid android:color="#CABBBBBB"/>
            <corners android:radius="@dimen/card_radius" />
        </shape>
    </item>

    <item
        android:left="0dp"
        android:right="0dp"
        android:top="0dp"
        android:bottom="2dp">
        <shape android:shape="rectangle">
            <solid android:color="@android:color/holo_purple"/>
            <corners android:radius="@dimen/card_radius" />
        </shape>
    </item>
</layer-list>

This drawable is meant to be used as a background for a card based UI, i.e. it will be the background for each view in a vertical list of views, causing them all to look like cards.

My problem is that the color of the cards is predefined in the drawable, so basically they will all be purple. What i would like is to be able to customize it from the view itself, something like this:

<TextView
    android:text="@string/hello_world"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/card_background"
    <!--over here maybe something like:-->
    card_background:color="the color i want"
    android:layout_gravity="center"
    android:gravity="center"
    android:padding="15dp"
    />

Is this possible? In effect i would be creating a template of a drawable...

1
  • I am looking for something similar. One way to do it off my mind is to write a custom TextView class Commented May 19, 2015 at 13:25

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.