Thursday, 1 January 2015

Can several buttons with background drawable behaviour be defined on the same button.xml archive?



It's my first post. My question is the next. I have several buttons with personalized drawable image and I also want to define their behaviour. For example:


Layout xml:



<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/text"
android:background="@drawable/boton" />


Drawable boton.xml:



<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://ift.tt/nIICcg">

<item android:drawable="@drawable/btnanadir3"
android:state_pressed="true" />

<item android:drawable="@drawable/btnanadir2"
android:state_focused="true" />

<item android:drawable="@drawable/btnanadir1" />
</selector>


Till now it's Ok, but I want 9 buttons like this with different images and my question is if it exists any way to have all buttons on the same boton.xml or I have to have all buttons drawable behaviour in diferent boton.xml for each one? For example boton.xml, boton2.xml, boton3.xml... boton9.xml and have the drawable folder with 9 boton.xml archives?


Thanks


No comments:

Post a Comment