is there any way to putting my custom buttons in one XML file in android?

Go To


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="" >
 <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="" 
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?

2012-04-03 21:04
by Nada
an example of what you are trying to achieve would help to get better answer - Diego Torres Milano 2012-04-03 21:58


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 Buttons that you create inside of your XML within other layouts using those themes.

<LinearLayout ... >
   <Button style="@style/customButtonStyle1" ... other attributes />

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.

2012-04-03 21:13
by Jon O
I'm using selector, and I have multiple buttons, when the button pressed will change to another image. Do I used this selector for all buttons, or should I use different selector for each one and that definitely so hard because I have maybe more than 50 button - Nada 2012-04-06 13:51
I think you can apply the selector to just the button itself (i.e., make it so the button color changes when pressed via selector), if you don't care about having different selection states for the actual image on the button. If you want different selector states for each image, you'll need a selector for each image - Jon O 2012-04-06 15:54