Android QuickStart
This Android QuickStart will give you an introduction to the Xojo development environment and lead you through the development of a working Android app, a simple web browser. It should take you 15 minutes or less to complete this.
Android development requirements
To run, test and debug an Android project you create in Xojo requires that Google's Android Studio development tool be installed but you will not have to use it. If you have not yet downloaded and installed Android Studio yet, do that now before continuing with the QuickStart.
Important
Make sure you quit Android Studio after installing it and before running an Android project in Xojo. Otherwise, you won't be able to run your Android project.
Shortcuts
We've provided a video of the QuickStart, in case you'd rather watch than go through the steps yourself.
You can download
the finished Xojo project as well if you'd prefer.
Getting started
Launch Xojo. After it finishes loading, the Project Chooser window appears.
Click on Android to select it.
You see three fields that need values:
Application Name will be the filename of the actual app file that you create.
Company Name is the name of your company. You may choose to leave this blank.
Application Identifier is a unique identifier for this app.
Enter
SimpleBrowser
as the Application Name.Click Create to open the Workspace, the main Xojo window, where you will begin designing your app.
Making the simple browser app
Overview
A Xojo app consists of a collection of objects, called classes. Nearly everything in Xojo is a class, including screens and controls. In the SimpleBrowser project, you use the default Screen class to create your screen and you add controls (user interface classes) to the screen to create the design.
The app uses three controls:
TextField: A TextField control is used to enter text. In this project, the URL to display is typed into a TextField at the top of the screen.
Button: A Button is used to trigger an action. The user presses the button to load the web page at the URL into the HTML Viewer.
HTML Viewer: An HTML Viewer is used to display a web page.
Building the user interface
With Screen1 open in the Layout Editor, you are ready to start adding controls to the screen.
In the Library, click on the TextField icon and drag it to the top-left corner of the screen in the Layout Editor. As you get close to the edges of the screen, you will see alignment indicators that help you position the control.
In the Library, click on the Button icon and drag it to the top-right corner of the screen.
In the Library, click on the HTML Viewer icon and drag it to the middle of the screen. Resize the control (using the selection handles so that it fills the screen below the TextField and Button).
Resize the TextField so that it is larger. Click on it to show the selection handles. Click the center-right handle and drag it to the right until the alignment guides tell you it is close enough to the Button.
Your finished screen layout should look like this:
Setting the properties
A property is a value of a class. Changing property values allows you to change the behavior of the class.
Inspector
The Inspector is used to change screen and control properties. It shares the same area on the right of the Workspace as the Library.
Setting the properties for the screen
In order to show the Inspector, click the Inspector button on the toolbar or press ⌘ I (Ctrl I on Windows and Linux).
In the Layout Editor, click on the Screen1 (not on any control) to select it. The Inspector now shows the properties for the screen.
In the Name field (located in the ID group), change the name from
Screen1
toBrowserScreen
. Press RETURN to see the name change in the Navigator.In the Title field, change the name to
SimpleBrowser
.
Setting the properties for the TextField
The TextField is where your user enters the URL they want to see in the browser.
In the Navigator, select the TextField1 control on BrowserScreen. The Inspector changes to show the TextField properties.
Change the Name property from
TextField1
toURLField
.Change the InputType property to URL. This displays the special URL keyboard on the Android device when the user taps in the field.
Change the Text property to
https://wikipedia.org
.
Setting the properties for the button
When running the app, pressing the button displays the web page.
On BrowserScreen, select the Button1 control. The Inspector changes to show the Button properties.
In the Name field, change the name from
Button1
toShowButton
.Give your button a caption by changing the Caption field from
Button
toShow
.
Adding code
Your app is almost complete. Now it is time to add the code that will tell the HTML Viewer (called WebViewer) the web page to display.
Follow these steps to add the code:
On BrowserScreen, double-click the ShowButton control. It's labelled "Show".
The Add Event Handler window appears. Event Handlers occur when the user initiates an action. In this case, when a user presses on a Button, your app runs any code in its Pressed event handler. Select Pressed from the Event Handler list and click OK. Notice the Navigator updates to show the Pressed event underneath the ShowButton control and the Code Editor displays.
Now you need to get the URL that the user typed. The value that a user types into a TextField is stored in the Text property of the TextField. Then you want to have the WebViewer display the web page. This is done by calling the LoadURL method of the HTML Viewer control and sending it the URL that the user typed. So, you need to add this code to the Code Editor. Start by clicking in the white space below the Pressed event name and then type this code (do type it rather than copy and pasting it):
WebViewer.LoadURL(URLField.Text)
That's it! Your first app is complete.
Saving your work
Before you go any further, save your work:
Save the project by choosing File > Save As.
Click Save.
Running your project
Click the Run button in Xojo to run the app in the Android Simulator. It may take a minute for the Android emulator to load.
Type a (secure, https) URL of your choice (or use the default) and click the Show button.
You will see the web page.
When you are finished experimenting with the Simple Browser app, you can quit the Android Simulator to return to Xojo.
What's next
This QuickStart has introduced you to Xojo and showed you how to make a simple app. Next, try the Android Tutorial that walks you through building a Task Manager app.
For more details, view the Topics and API sections of the documentation.