xml - Android: Can I re-use a layer-list? -
when implementing selectors buttons , listview items, keep finding want reuse same item/background state_pressed , state_focused.
instead of duplicating xml 'code', possible re-use ?
e.g. here state_pressed 'code' - how can state_focused use same lump of 'code' without duplicating all?
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true"> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <!-- pds: side lowlight lines inset hidden underneath solid colour --> <item android:bottom="0dp" android:right="0dp" android:top="0dp" android:left="0dp"> <shape> <solid android:color="#00000000" /> <stroke android:color="@color/butgreyselectframe" android:width="4dp"/> <corners android:radius="4dp" /> </shape> </item> <!-- pds: solid colour --> <item android:left="4dp" android:right="4dp" android:top="4dp" android:bottom="4dp"> <shape> <solid android:color="@color/butgreyselectback" /> <padding android:left="10dp" android:top="10dp" android:right="10dp" android:bottom="10dp" /> </shape> </item> </layer-list> </item>
yes, drawable can reused in selector.
just create separate file layer-list
, reference with
<item android:state_xxx android:drawable="@drawable/the_resource" />
Comments
Post a Comment