O'Reilly logo

Appcelerator Titanium Smartphone App Development Cookbook - Second Edition by Jason Kneen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating Buttons and Labels using Events

So far, we've looked at a basic project and creating Windows and Views. Now, let's look at creating some Labels and Buttons and adding some click events.

How to do it...

Keep the index.xml that you created for the last recipe. Let's modify it a little to add some labels and buttons. Change the code to the following:

<Alloy>
  <Window backgroundColor="white" layout="vertical">
    <Label id="myLabel" borderRadius="2" top="40" borderColor="#CCC" height="35" width="200"/>
    <Button id="myButton" borderRadius="2" backgroundColor="#35e" color="#fff" top="10" height="35" width="100">Click me!</Button>
  </Window>
</Alloy>

Build the app in the simulator to see the following:

Notice that we're using a vertical layout to make ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required