I'm developing an android application that contain many custom buttons. Do I need to make an .xml file for each one or there is a way of putting all of them in one .xml file?
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_pressed="true" android:drawable="@drawable/father2" ></item>
<item android:drawable="@drawable/father" ></item>
Can I use this code for multiple custom buttons in one xml file?
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false" >
<item android:drawable="@drawable/brother1" android:duration="200"/>
<item android:drawable="@drawable/brother2" android:duration="200"/>
<item android:drawable="@drawable/brother3" android:duration="200"/>
<item android:drawable="@drawable/brother4" android:duration="200"/>
<item android:drawable="@drawable/brother5" android:duration="200"/>
And I also have an animated list; can I use multiple animated lists in one xml file?
It depends what part of your button is custom. If only the image or text is custom, you could put them inside of res/styles.xml
and then theme the Button
s that you create inside of your XML within other layouts using those themes.
<LinearLayout ... >
<!--stuff-->
<Button style="@style/customButtonStyle1" ... other attributes />
</LinearLayout>
If they have different states (e.g., pressed, selected, unselected) you can use a <selector>
resource to assign values (images, text) to the different states. A quick google shows this tutorial for selectors.