Miért nem működik a következő?
convertView.setBackgroundResource(R.drawable.list_background1);
list_background1.xml ->
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Normal state. -->
<item android:drawable="@drawable/listitem_bg1" android:state_pressed="false" android:state_selected="false"/>
<!-- pressed state. -->
<item android:drawable="@drawable/listitem_bg_pressed" android:state_pressed="true" android:state_selected="false"/>
<!-- Selected state. -->
<item android:drawable="@drawable/listitem_bg_selected" android:state_pressed="false" android:state_selected="true"/>
</selector>
drawable/listitem_bg1.xml ->
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:angle="180"
android:endColor="?attr/attr_list_item_background1"
android:startColor="?attr/attr_list_item_background2"/>
<corners android:radius="6dp"/>
</shape>
attr.xml ->
<?xml version="1.0" encoding="utf-8"?>
<resources>
<attr name="attr_list_item_background1" format="reference" />
<attr name="attr_list_item_background2" format="reference" />
<attr name="attr_list_item_background_head" format="reference" />
<attr name="attr_shape_radius" format="reference" />
</resources>
styles.xml ->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="attr_list_item_background1">@color/list_row_even</item>
<item name="attr_list_item_background2">@color/list_row_odd</item>
<item name="attr_list_item_background_head">@color/list_row_head</item>
</style>
Amennyiben kihagyom az attr.xml használatát és a pl.
android:endColor="?attr/attr_list_item_background1" helyet rögtön a színre mutatok android:endColor="color/list_row_even", akkor működik, de akkor nem tudok több témát létrehozni.