转载请注明出处: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. iOS开发UI篇--一个侧滑菜单SlidingMenu

    一.简介 侧滑菜单已经成为app一个极常用的设计,不管是事务类,效率类还是生活类app.侧滑菜单因Path 2.0和Facebook为开发者熟知,国内目前也有很多流行app用到了侧滑菜单,比如QQ.网 ...

  2. swift项目第五天:swift中storyBoard Reference搭建主界面

    一:StoryBoard Reference的介绍 StoryBoard Reference是Xcode7,iOS9出现的新功能 目的是让我们可以更好的使用storyboard来开发项目 在之前的开发 ...

  3. 1、第一课 register_chrdev和register_chrdev_region 创建知识

    1. register_chrdev注册字符设备后,有0-256个子设备可用,若major==0,则内核动态申请主设备号.static inline int register_chrdev(unsig ...

  4. OCulus Rift 游戏开发六原则

    本文章由cartzhang编写,转载请注明出处. 所有权利保留. 文章链接:http://blog.csdn.net/cartzhang/article/details/46685477 作者:car ...

  5. spark安装与调试

    I---- 1---jdk and scala install ****zyp@ubuntu:~/Desktop/software$ tar xvf jdk-7u67-linux-i586.tar.g ...

  6. 程序猿学英语——In September the English learning summary

    转眼间9月份又过去了,又该好好总结一下这个月的英语学习情况了. 在暑假快结束的时候.9期师姐给我们測了英语快照.当初測的时候就发现一个问题:当測自己听过尤其是读过的东 西的时候,自己都能听出来.測自己 ...

  7. Python 线程启动的四种方式

    import threading,_thread def action(i): print(i **32) #带有状态的子类 class Mythread(threading.Thread): def ...

  8. 远离“精神乞丐”(IBM的前CEO郭士纳把员工分为四种类型)

    语音丨吴伯凡 乞丐与其说是一种身份, 不如说是一种精神状态, 习惯性索取且心安理得, 习惯性寻求安慰,习惯性抱怨, 与之截然对立的, 是“操之在我”(Proactive)的精神, 乞丐型员工是公司内部 ...

  9. mui列表跳转到详情页优化方案

    原理 因为列表页到详情页是多对一的形式,即列表页的多条数据列表对应的是一个详情页,只是数据不同而:因此,可以在加载列表页时预加载详情页,即创建一个详情页的webview,但是不显示出来,点击列表的时候 ...

  10. Java多线程编程— 概念以及经常使用控制

    多线程能满足程序猿编写很有效率的程序来达到充分利用CPU的目的,由于CPU的空暇时间可以保持在最低限度.有效利用多线程的关键是理解程序是并发运行而不是串行运行的.比如:程序中有两个子系统须要并发运行, ...