转载请注明出处:http://blog.csdn.net/dawanganban/article/details/9822431

Building Your First App

GETSTARTED

DEPENDENCIESAND PREREQUISITES

·     Android SDK

·     ADT Plugin 20.0.0 or higher (if you're
usingEclipse)

Welcome toAndroid application development!

This classteaches you how to build your first Android app. You’ll learn how to create anAndroid project and run a debuggable version of the app. You'll also learn somefundamentals of Android app design, including
how to build a simple userinterface and handle user input.

Before you startthis class, be sure you have your development environment set up. You need to:

1.   Download the Android SDK.

2.   Install the ADT plugin for Eclipse (if you’ll use theEclipse IDE).

3.   Download the latest SDK tools and platforms using the SDKManager.

If you haven'talready done these tasks, start by downloading the Android SDK andfollowing
the install steps. Once you've finished the setup, you're ready tobegin this class.

This class usesa tutorial format that incrementally builds a small Android app that teachesyou some fundamental concepts about Android development, so it's important thatyou follow each step.

建立你的第一个应用程序

依赖性和先决条件

·     android
sdk

·     ADT插件20
0 0或更高(如果您使用Eclipse)

欢迎来到Android应用程序开发!

本教程会教你如何建立你的第一个Android应用程序。您将学习如何创建一个Android项目并调试应用程序,你还将学习一些Android应用程序设计的基础,包括如何构建一个简单的用户界面和处理用户输入。

在你开始本教程之前,请确保你已经搭建好开发环境。你需要:

1.   下载Android SDK。

2.   Eclipse的ADT插件安装 (如果你使用的是Eclipse
IDE)。

3.   下载最新的SDK工具和平台使用SDK管理器

如果您尚未完成这些任务,开始下载android
sdk
并完成安装步骤。如果你完成了设置,准备开始本课程的学习。

本课程将通过使用一个小型的android应用,教你一些基本概念和安卓开发过程,所以遵循每一步的操作都至关重要。

开始第一课;

Creating an Android Project

PREVIOUSNEXT

THIS LESSONTEACHES YOU TO

1. Create a Project with Eclipse

2. Create a Project with Command Line Tools

YOU SHOULD ALSOREAD

·      Installing the SDK

·      Managing Projects

An Android projectcontains all the files that comprise the source code for your Android app. TheAndroid SDK tools make it easy to start a new Android project with a set ofdefault project directories and files.

This lesson showshow to create a new project either using Eclipse (with the ADT plugin) or usingthe SDK tools from a command line.

Note: You shouldalready have the Android SDK installed, and if you're using Eclipse, you shouldalso have the ADT
plugin
installed (version 21.0.0 or higher). If you don't have these, follow theguide to Installing the Android SDK before
you start this lesson.

Create a Project with Eclipse


1. Click New  inthe
toolbar.

2. In the window thatappears, open the Android folder,select Android Application Project,and click Next.

Figure 1. The New Android App Project wizard in Eclipse.

3. Fill in the formthat appears:

o   ApplicationName is the app name thatappears to users. For this project, use "My First App."

o   ProjectName is the name of your projectdirectory and the name visible in Eclipse.

o   PackageName is the package namespacefor your app (following the same rules as packages in the Java programminglanguage). Your package name must be unique across all packages installed onthe
Android system. For this reason, it's generally best if you use a name thatbegins with the reverse domain name of your organization or publisher entity.For this project, you can use something like"com.example.myfirstapp." However, you cannot publish your app
on GooglePlay using the "com.example" namespace.

o   MinimumRequired SDK is the lowest version ofAndroid that your app supports, indicated using the API
level
. To support as many devices as possible, you should set this to thelowest version available that allows your app to provide its core feature set.If any feature of your app is possible only on newer versions of Android andit's not critical
to the app's core feature set, you can enable the featureonly when running on the versions that support it (as discussed in Supporting
Different Platform Versions
). Leave this set to the default value for this project.

o   TargetSDK indicates the highestversion of Android (also using the API
level
) with which you have tested with your application.

As new versions of Android become available, you shouldtest your app on the new version and update this value to match the latest APIlevel in order to take advantage of new platform features.

o   CompileWith is the platform versionagainst which you will compile your app. By default, this is set to the latestversion of Android available in your SDK. (It should be Android 4.1 or greater;if
you don't have such a version available, you must install one usingthe SDK Manager). You can still build your
app to support older versions, but setting thebuild target to the latest version allows you to enable new features andoptimize your app for a great user experience on the latest devices.

o   Theme specifies the Android UI style to apply for yourapp. You can leave this alone.

Click Next.

4. On the next screento configure the project, leave the default selections and click Next.

5. The next screencan help you create a launcher icon for your app.

You can customize an icon in several ways and the toolgenerates an icon for all screen densities. Before you publish your app, youshould be sure your icon meets the specifications defined in the Iconography design
guide.

Click Next.

6. Now you can selectan activity template from which to begin building your app.

For this project, select BlankActivity andclick Next.

7. Leave all thedetails for the activity in their default state and click Finish.

Your Androidproject is now set up with some default files and you’re ready to beginbuilding the app. Continue to the next
lesson
.

Create a Project with Command Line Tools


If you're notusing the Eclipse IDE with the ADT plugin, you can instead create your projectusing the SDK tools from a command line:

1. Change directoriesinto the Android SDK’s tools/ path.

2. Execute:

android list targets

This prints a list of the available Android platformsthat you’ve downloaded for your SDK. Find the platform against which you wantto compile your app. Make a note of the target id. We recommend that you selectthe highest version possible. You
can still build your app to support olderversions, but setting the build target to the latest version allows you tooptimize your app for the latest devices.

If you don't see any targets listed, you need to installsome using the Android SDK Manager tool. See Adding
Platforms and Packages
.

3. Execute:

4.  android create project --target<target-id> --name MyFirstApp \

5.  --path<path-to-workspace>/MyFirstApp --activity MainActivity \

6.  --package com.example.myfirstapp

Replace <target-id> with an id from the list of targets (from the previous step) andreplace <path-to-workspace> with the location in which you want to save yourAndroid projects.

Your Androidproject is now set up with several default configurations and you’re ready tobegin building the app. Continue to the next
lesson
.

Tip: Addthe platform-tools/ as well as the tools/ directory to your PATH environmentvariable.

创建一个Android项目

这节课教你

1.  使用Eclipse创建一个项目

2.  使用命令行工具创建项目

你也应该阅读

·     安装SDK

·     管理项目

Android项目包含的所有文件,包括你的Andr​​oid应用程序的源代码。 AndroidSDK的工具,可以让构建Andr​​oid项目与默认项目目录和文件变的更便捷和简单。

本课将说明如何使用Eclipse ADT插件或使用SDK命令行工具创建一个新的项目。

注意:你应该已经安装了Android SDK,如果你使用Eclipse,你应该也有安装ADT插件 (21.0.0或更高版本)。 如果你没有这些,按照安装指南安装Android
SDK
 ,然后再开始本课学习。

使用Eclipse创建一个项目


1.   点击“ 新建”  在工具栏。

2.   在出现的窗口中,打开Android的文件夹,选择“Android Application ,并单击” 下一步“。



图1:新的Android应用程序在Eclipse项目向导。

3.   填写的形式出现:

o   Application Name给用户展示的应用程序的名称。 对于这个项目,使用“My
First App”

o   Project Name您的项目在Eclipse中可见的目录和名称。

o   Package Name是包的命名空间,为您的应用程序(在Java编程语言遵循相同的包规则)。 你的包的名称必须是在Android系统上安装的所有软件包中唯一的。 出于这个原因,如果您使用与您的组织或出版实体的反向域名作为包名通常是最好的。对于这个项目,你可以使用例如“com.example.myfirstapp” 但是,您不能使用
“com.example”作为命名空间来发布您的应用程序。

o   MinimumRequired SDK您的应用程序支持的Android SDK是最低版本,表明API的版本高低 。 为了尽可能的支持多的设备,你应该设定这个最低版本为可以让您的应用程序提供其核心功能的最低版本。 如果您的应用程序的核心功能集在新版本的Android和其他版本都支持,当在不同版本可以支持时可以使用该功能(如支持不同的平台版本 )。 将此设定为这个项目的默认值。

o   Target SDK表明您测试您的应用程序的Android(也使用API级别 )的最高版本。

随着新版本Andr​​oid的使用,您应该在新版本上测试应用程序来更新此值,以符合最新的API级别,以充分利用新的平台功能。

o   Compile With编译您的应用程序的平台版本。 默认情况下,此设置为您的Andr​​oid
SDK提供的最新版本。 (应该是Android 4.1或更高版本,如果你没有这样的版本,您必须安装一个使用SDK管理器 )。 您也可以建立你的应用程序来支持旧版本,但设置构建目标到最新版本可以让用户体验最新设备的功能和您对应用程序的优化。

o   Theme指定申请您的应用程序的Android UI风格。 你可以忽略这一项。

单击“ 下一步 ”。

4.   在下一屏幕配置项目,保留默认选项,并单击“ 下一步”。

5.   下一个屏幕,可以帮助您创建一个启动你的应用程序的图标。

您可以自定义图标在几个方面,该工具会生成一个图标,所有的屏幕密度。 在您发布您的应用程序之前,你应该确保你的图标符合设计规范。

单击“ 下一步 ”。

6.   现在您可以选择构建应用程序的动态模板。

对于这个项目,选择BlankActivity,并单击“ 下一步”。

7.   保留所有为默认,并单击 Finish。

现在你的Andr​​oid项目生成了一些默认的文件,准备好开始构建你的应用程序。 继续下一课 。

使用命令行工具创建项目


如果你不使用Eclipse IDE ADT插件,可以改为使用SDK命令行工具来创建你的项目:

1.   改变当前目录到Android SDK的tools/路径。

2.   执行:

Android listtargets

打印你已经下载的SDK可用的Andr​​oid平台列表。 找到编译你的应用程序的平台。 请记下平台的id。 我们建议您选择可能的最高版本。 您也可以建立支持旧版本的应用程序,但设置构建目标到最新版本,可以优化你的应用程序。

如果你没有看到任何平台列表,你需要使用Android SDK管理器安装一些工具。 请参阅添加平台和软件包 。

3.   执行:

android create project --target <target-id> --name MyFirstApp \
--path <path-to-workspace>/MyFirstApp --activity MainActivity \
--package com.example.myfirstapp



用目标平台的id(前面的步骤)更换<target-id>,并更换<path-to-workspace>为要保存你的Android项目的位置。

现在你的Andr​​oid项目设置了几个默认的配置,你准备好开始构建应用程序。 继续下一课 。

Android官方教程翻译(1)——创建第一个Android应用的更多相关文章

  1. Android官方教程翻译(3)——创建一个简单的用户界面

    转载请注明出处:http://blog.csdn.net/dawanganban/article/details/9839523 Building a Simple User Interface 创建 ...

  2. Android官方教程翻译(4)——启动另一个Activity

    Starting Another Activity 启动另一个Activity PREVIOUSNEXT THIS LESSON TEACHES YOU TO 这节课教你 1.   Respond t ...

  3. Android官方教程翻译(6)——添加ActionBar

    The action bar allows you to add buttons for the most important action items relating to the app's c ...

  4. Android官方教程翻译(2)——运行第一个程序

    转载请注明出处:http://blog.csdn.net/dawanganban/article/details/9823623 Running Your App PREVIOUSNEXT THIS ...

  5. Android官方教程翻译(5)——设置ActionBar

    Setting Up the Action Bar 设置Action Bar PREVIOUSNEXT THIS LESSONTEACHES YOU TO 这节课教你 1.    Support An ...

  6. Asp.Net MVC4.0 官方教程 入门指南之四--添加一个模型

    Asp.Net MVC4.0 官方教程 入门指南之四--添加一个模型 在这一节中,你将添加用于管理数据库中电影的类.这些类是ASP.NET MVC应用程序的模型部分. 你将使用.NET Framewo ...

  7. Asp.Net MVC4.0 官方教程 入门指南之三--添加一个视图

    Asp.Net MVC4.0 官方教程 入门指南之三--添加一个视图 在本节中,您需要修改HelloWorldController类,从而使用视图模板文件,干净优雅的封装生成返回到客户端浏览器HTML ...

  8. 创建第一个Android项目

    目录 创建第一个Android项目 创建HelloWorld项目 选择模板 选择模板界面的英文翻译 配置项目 配置项目界面英文翻译及解释 配置项目界面的注意事项 Name的命名规范 Package n ...

  9. 用Kotlin创建第一个Android项目(KAD 01)

    原文标题:Create your first Android project using Kotlin (KAD 01) 作者:Antonio Leiva 时间:Nov 21, 2016 原文链接:h ...

随机推荐

  1. 《ECMAScript6入门》笔记——Generator函数

    今天在看<ECMAScript6入门>的第17章——Generator函数的语法.理解起来还是有点费劲,几段代码看了很多遍.总算有点点理解了. 示例代码如下:(摘自阮一峰<ECMAS ...

  2. 请求筛选模块被配置为拒绝包含 hiddenSegment 节的 URL 中的路径

    转自原文 请求筛选模块被配置为拒绝包含 hiddenSegment 节的 URL 中的路径. 打开C:\Windows\System32\inetsrv\config路径 找到applicationH ...

  3. 为什么一款优秀的移动工具类应用必须开发PCclient?

    移动大潮气势汹汹,PC端似乎已经一条腿跨进了坟墓. 作为一个windows开发者.难免有些焦灼. windows真的已死吗?真的无用武之地了吗? 或许是人云亦云吧. 突然看到了这篇文章,感触颇深. 文 ...

  4. 安装及XShell软件的配置

    Linux系统centOS7在虚拟机下的安装及XShell软件的配置   前面的话 本文将详细介绍Linux系统centOS7在虚拟机下的安装 准备工作 [系统下载] 在安装centOS7之前,首先在 ...

  5. Voronoi Diagram——维诺图

    Voronoi图定义   任意两点p 和q 之间的欧氏距离,记作 dist(p, q) .就平面情况而言,我们有           dist(p, q) =  (px-qx)2+ (py-qy)2 ...

  6. js课程 2-7 带默认参数的函数怎么写

    js课程 2-7 带默认参数的函数怎么写(注意参数顺序) 一.总结 一句话总结:默认参数一定要放在最后面,而且还有注意你调用参数的时候给参数的顺序习惯.直接加个等于号就可以是默认参数.function ...

  7. (九)RabbitMQ消息队列-通过Headers模式分发消息

    原文:(九)RabbitMQ消息队列-通过Headers模式分发消息 Headers类型的exchange使用的比较少,以至于官方文档貌似都没提到,它是忽略routingKey的一种路由方式.是使用H ...

  8. html css div img垂直居中

    <head> <meta charset="UTF-8"> <meta name="Generator" content=&quo ...

  9. RocketMQ 安装详细说明

    原文:RocketMQ 安装详细说明 目录 本文导读 环境说明 RocketMQ 下载 从 Apache 下载 从 GitHub 下载 RocketMQ 安装 文件上传 项目解压 编译部署 Rocke ...

  10. SpringMVC接受参数若干问题

    最近2年在工作问题总结中,好几次遇到了SpringMVC接收参数的问题,今天特别总结下.  SpringMVC接收参数的方法:  Html参数输入: <input name="stat ...