1. Using Eclipse, create a new project by selecting File ➪ New ➪ Project . . . (see Figure 1-23).
FIGURE 1-23
2.
Expand the Android folder and select Android Project (see Figure 1-24). Click Next.
Expand the Android folder and select Android Project (see Figure 1-24). Click Next.
FIGURE 1-24
3. Name the Android project HelloWorld, as shown in Figure 1-25, and then click Next.
FIGURE 1-25
4. Select the Android 4.0 target and click Next.
5. Fill in the Application Info details as shown in Figure 1-26. Click Finish.
FIGURE 1-26
6. The Eclipse IDE should now look like Figure 1-27.
FIGURE 1-27
7. In the Package Explorer (located on the left of the Eclipse IDE), expand the HelloWorld project by clicking on the various arrows displayed to the left of each item in the project (see Figure 1-28). In the res/layout folder, double-click the main.xml file.
FIGURE 1-28
8. The main.xml file defines the user interface (UI) of your application. The default view is the Layout view, which lays out the activity graphically. To modify the UI by hand, click the main.xml tab located at the bottom (seeFigure 1-29).
FIGURE 1-29
9. Add the following code in bold to the main.xml file:
<?xml version=”1.0” encoding=”utf-8”?>
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”
android:orientation=”vertical” >
<TextView android:layout_width=”fill_parent” android:layout_height=”wrap_content” android:text=”@string/hello” />
<TextView android:layout_width=”fill_parent” android:layout_height=”wrap_content”
android:text=”This is my first Android Application!” />
<Button android:layout_width=”fill_parent” android:layout_height=”wrap_content” android:text=”And this is a clickable button!” />
</LinearLayout>
10. To save the changes made to your project, press Ctrl+S.
11. You are now ready to test your application on the Android emulator. Right-click the project name in Eclipse and select Run As ➪ Android Application (see Figure 1-30).
FIGURE 1-30
12. If you have not made any mistakes in the project, you should now be able to see the application installed and running on the Android emulator (see Figure 1-31).
FIGURE 1-31
13. Click the Home button (the house icon in the lower-left corner above the keyboard) so that it now shows the Home screen (see Figure 1-32).
FIGURE 1-32
14. Click the application launcher icon to display the list of applications installed on the device.
Note that the HelloWorld application is now installed in the application launcher (see Figure 1-33).
FIGURE 1-33
Không có nhận xét nào:
Đăng nhận xét