搭建Android 开发环境
Android一词的本义指“机器人”,Android是Google于07年11月5日宣布的基于Linux平台开源手机操作系统名称,该平台由操作系统、中间件、用户界面和应用软件组成。在国内,联想、戴尔、多普达、飞利浦、中兴、三星、摩托罗拉、等厂商已经推出基于Android平台的智能手机。
环境搭建:
准备工作:安装JDK并配置,这里不做详解。
1.Eclipse平台环境搭建。我的Eclipse版本是3.4.2
(1)打开Eclipse,点击"Help菜单"选择"Software Updates.."项
2.进入"Available Software页,点击"Add Site"项,在地址栏中输入:https://dl-ssl.google.com/android/eclipse,点击"OK".
这时会看到如下添加了一项,选中此项,单击"Install"
开发android的第一个应用
1.创建Helloword Android 项目
ADT提供了生成Android 应用程序框架的功能,可以使用ADT通过Eclipse很容易创建一个Android工程。
1.打开Eclipse,新建项目(点击FileàNewàProject),在项目列表中展开Android目录,选择Android Project,如下
点击”finish”即可完成项目的创建,创建后的项目已经是一个可运行的Android应用,我们可以通过下面方式运行此应用:
点击工具栏上手机形状的虚拟设备管理器(简称“AVD“),如下:
在打开的虚拟设备管理器中创建一个虚拟手机:
安装完成后重启,看到工具栏中加了图5,图6中的俩项
打开"Preferences",点击"Android"在"SDK Location:"中输入Android SDK包的目录,点击“Apply”,会看到图8界面
6.点击图5中的机器人,打开插件模拟器的界面,点击“New”开始输入要创建的模拟器的信息。
Name是模拟器的名称可随便填
Target是模拟器的SDK版本,目前最新是2.2.
其他是硬件参数,一般都是默认。
.点击“Create AVD”后插件完成,这时会看到多了一项。
.测试是否成功
Android应用程序入门
新建一个android project
Project name :helloword1然后点击next(下一步)
(创建出一个新的helloword1图标。)
<helloword1 Manifes>
<?xml version="1.0" encoding="utf-8"?><!-- xml头 xml name space -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="cn.csdn.hr.activity"
android:versionCode="1"
android:versionName="1.0" >
<!-- 使用 sdk版本10 -->
<uses-sdk android:minSdkVersion="10" />
<!-- 应用程序android:icon="@引用" -->
<application
android:icon="@drawable/jingling"
android:label="@string/app_name" >
<activity
android:name=".Helloword1Activity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>(更换图片helloword1)
把dog转化为机器狗:(代码)
<?xml version="1.0" encoding="utf-8"?><!-- xml头 xml name space -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="cn.csdn.hr.activity"
android:versionCode="1"
android:versionName="1.0" >
<!-- 使用 sdk版本10 -->
<uses-sdk android:minSdkVersion="10" />
<!-- 应用程序android:icon="@引用" -->
<application
android:icon="@drawable/dog"
android:label="@string/dog" >
<activity
android:name=".Helloword1Activity"
android:label="@string/dog" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
(修改为第一个应用程序)
创建按钮:
<?xml version="1.0" encoding="utf-8"?><!-- xml头 xml name space -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="cn.csdn.hr.activity"
android:versionCode="1"
android:versionName="1.0" >
<!-- 使用 sdk版本10 -->
<uses-sdk android:minSdkVersion="10" />
<!-- 应用程序android:icon=“@引用” -->
<application
android:icon="@drawable/dog"
android:label="@string/dog" >
<!-- 代表的是一个活动 就是手机的一屏 -->
<activity
android:name=".HelloworldsActivity"
android:label="@string/dog" >
<!-- intent-filter告诉手机 谁是主程序 -->
<intent-filter>
<!-- action动作 android.intent.action.MAIN 程序入口 -->
<action android:name="android.intent.action.MAIN" />
<!-- 种类 -->
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Main.xml:
<?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/dog" />
<Button
android:id="@+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/strbtn" />
</LinearLayout>
String.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello World, HelloworldsActivity!</string>
<string name="app_name">Helloworlds</string>
<string name="first">第一个应用程序</string>
<string name="dog">机器狗</string>
<string name="strbtn">按钮</string>
</resources>