I have a layout border_bottom_black_bluegrey_background.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape android:shape="rectangle" >
<stroke
android:width="1dp"
android:color="@color/black" />
</shape>
</item>
<item android:bottom="1dp">
<shape android:shape="rectangle" >
<solid android:color="@color/blue_grey" />
</shape>
</item>
</layer-list>
I'm trying to reuse this layout so that I don't have to create one for each different border and background color.
I know this can be accomplished with styles and attrs, I had a look on the internet for good tutorial but with no avail.
This is what i've got so far:
attrs.xml
<resources>
<declare-styleable>
<attr name="backgroundColor" format="reference"/>
<attr name="borderColor" format="reference"/>
</declare-styleable>
</resources>
styles.xml
<style name="BorderBottom">
<item name="android:background">@drawable/border_bottom</item>
</style>
<style name="BlackBorderBlueGreyBackground" parent="BorderBottom">
<item name="borderColor">@color/black</item>
<item name="backgroundColor">@color/blue_grey</item>
</style>
border_bottom.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape
android:shape="rectangle">
<stroke android:width="1dp" android:color="@color/black" />
<solid android:color="?attr/borderColor" />
</shape>
</item>
<item android:bottom="1dp">
<shape
android:shape="rectangle">
<solid android:color="?attr/backgroundColor" />
</shape>
</item>
</layer-list>
My implementation of the style
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/BlackBorderBlueGreyBackground"
android:orientation="vertical" >
</RelativeLayout>
Can someone point me in the right direction?