Thứ Sáu, 25 tháng 4, 2014

Creating Your First Android Application [Getting Started with Android Programming]


1.     Using Eclipse, create a new project by selecting File  New  Project . . . (see Figure 1-23).


FIGURE 1-23

2.           
Expand  the Androi folder and select Androi Project (see Figure 1-24). Click Next.


FIGURE 1-24

3.           Name the Androi project HelloWorld, as shown in Figure 1-25, and then click Next.


FIGURE 1-25

4.     Select the Androi 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 arrow displayed to the left of each item in the project (see Figure 1-28). Ithe 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 thLayout view, which lays out the activity graphically To modify the UI by hand click thmain.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”?>
<LinearLayout xmlns:android=”http://schemas.android.com/apk/res/ android”
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  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 Androi emulator. Right-click the project namin Eclipse and select Run As  Androi 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 runnin on the Androi 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