1. 啟動Eclipse,點擊工具欄上的圖標(biāo)啟動創(chuàng)建Android項目向?qū)А?/p>
2. 在對話框中輸入項目名稱等信息,如下圖。
注意上面的對話框中Create Activity默認(rèn)是選中狀態(tài),點擊完成后會自動生成一個HelloAct的類。
HelloAct.java
package com.wm.helloandroid;
import android.app.Activity;
import android.os.Bundle;
public class HelloAct extends Activity {//繼承了Activity父類
/** 覆蓋了父類的onCreate方法, 在Activity第一次創(chuàng)建的時候調(diào)用 */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);//顯示界面
}
}
import android.app.Activity;
import android.os.Bundle;
public class HelloAct extends Activity {//繼承了Activity父類
/** 覆蓋了父類的onCreate方法, 在Activity第一次創(chuàng)建的時候調(diào)用 */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);//顯示界面
}
}
在gen/com/wm/helloandroid/目錄下根據(jù)資源數(shù)據(jù)自動生成了R.java,這個類不要修改
package com.wm.helloandroid;
public final class R {
public static final class attr {
}
public static final class drawable {
public static final int icon=0x7f020000;
}
public static final class layout {
public static final int main=0x7f030000;
}
public static final class string {
public static final int app_name=0x7f040001;
public static final int hello=0x7f040000;
}
}
public final class R {
public static final class attr {
}
public static final class drawable {
public static final int icon=0x7f020000;
}
public static final class layout {
public static final int main=0x7f030000;
}
public static final class string {
public static final int app_name=0x7f040001;
public static final int hello=0x7f040000;
}
}
在res/layout下自動生成一個main.xml文件中定義了界面布局。
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
</LinearLayout>
在res/values下自動生成一個strings.xml文件用來定義一些字符串,顏色,形狀等資源,供程序使用。
strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello World, HelloAct!</string>
<string name="app_name">Hello</string>
</resources>
<resources>
<string name="hello">Hello World, HelloAct!</string>
<string name="app_name">Hello</string>
</resources>
在項目根目錄下自動生成了AndroidManifest.xml。這個文件是每個Android應(yīng)用程序都必須配置文件,本例不需要改動。在項目根目錄下還自動生成default.properties,也是一個需要修改的文件。
3. 實際上,不需要寫任何代碼程序就可以運(yùn)行了。選擇項目名稱>>右鍵>>Run as>>Android Application運(yùn)行程序。

嘗試一下將strings.xml中
<string name="hello">Hello World, HelloAct!</string>
改為
<string name="hello">你好,Android</string>
再運(yùn)行程序試試。