A (175)

(Tuis.) #1
CHAPTER 9: Android Graphic Design: Making Your UI Designs Visual 347

Figure 9-32. Create an ibstates1.xml file with a parent tag and four child tags for button states



  1. Perform the same work process outlined in Figures 9-31 and 9-32 to create
    an ibstates2.xml and ibstates3.xml file referencing the imagebutton2state
    and imagebutton3state assets. This will be quite easy if you copy the XML
    markup you created for ibstates1.xml into the ibstates2.xml and ibstates3.
    xml file, and change instances of the number 1 to 2 and 3, respectively. I am
    naming these files using this naming convention for a very good reason!


Referencing Multi-State XML via activity_main


To put these new multi-state ImageButton UI elements into play (place) in your activity_main.xml
UI design, you will need to edit the android:src parameter to reference the XML definition files that
you created in the previous section. Make sure not to use the .xml file extension in your reference
file name. This new markup is shown in Figure 9-33, along with an android:background="#00000000"
(transparency value) parameter for each that will define the transparent background
color value. This background parameter will essentially remove that (default) square grey button
background from your ImageButton UI element, so that the image asset itself becomes the button,
which is why we are using the Android ImageButton class.

Free download pdf