http://www.cnblogs.com/chunhui588/archive/2010/07/10/hello-android.html------详细说明
一、设置Android SDK路径
在初建立Android 项目之前,需要设置Android SDK的路径,让Eclipse可以找到Android SDK,先执行“Window------Preferences”。弹出下图窗口,
设置 Android 的Preferences路径
点击Android的树型列表,单击“Browser”选择Android SDK的路径,然后点击“Apply”---“OK”。
二、 建立第一个Android项目~Hello Android!
Android SDK引用路径设置完毕之后就可以建立项目Hello Android了。
1、运行File > New > Project. 弹出下图窗口。
2、在上图窗口中选择"Android Project" 然后点击“Next”.弹出下图窗口
3、在窗口中填写如下内容:
Project name: HelloAndroid
Application name: Hello, Android
Package name: com.example.helloandroid (or your own private namespace)
Create Activity: HelloAndroid
然后点击“Finish”.
4、工程建立完毕,可以在其中加入部分显示。在工程的左面找到HelloAndroid.java 文件,其路径为 HelloAndroid > src > com.example.helloandroid,
下面是其原始语句:
package com.example.helloandroid;
import android.app.Activity;
import android.os.Bundle;
public class HelloAndroid extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
修改之后的语句:
package com.example.helloandroid;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class HelloAndroid extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView tv = new TextView(this);
tv.setText("Hello, Android");
setContentView(tv);
}
}
5、运行应用程序
Eclipse 使得运行应用程序很方便:
1、在左边选中工程名称
2、选择 Run > Run As> Android Application
假若此时尚未将手机与计算机联机,那么Eclpise将打开默认的Android模拟器(Emulator),运行画面就如同真的手机开机一样,随着计算机硬件环境的不同,运行模拟器也会有不同的性能表现,开机之后,界面如下:
然后点击menu键,随即打开刚建立好的Hello World程序。
要退出被启动的"Hello World"程序,可以按下手机模拟器上的退格键(Backspace)。