ImageVerifierCode 换一换
格式:DOCX , 页数:11 ,大小:176.07KB ,
资源ID:4026246      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/4026246.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(构建你的第一个Android应用程序.docx)为本站会员(b****4)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

构建你的第一个Android应用程序.docx

1、构建你的第一个Android应用程序编写你的第一个Android应用程序2012-10-3 翻译:罗奕聪注意:這篇文章的一部分基於Android開放原始碼計劃(Android Open Source Project),這部分內容在知識共享 姓名標示 2.5 (CC BY 2.5) 許可下發佈此內容在知識共享 姓名標示-非商業性-相同方式分享 3.0 Unported (CC BY-NC-SA 3.0) 許可下發佈。一、创建一个Android工程An Android project contains all the files that comprise the source code for

2、your Android app. The Android SDK tools make it easy to start a new Android project with a set of default project directories and files.This lesson shows how to create a new project either using Eclipse (with the ADT plugin) or using the SDK tools from a command line.Create a Project with EclipseIn

3、Eclipse, click New Android App Projectin the toolbar.Figure 1.The New Android App Project wizard in Eclipse.1. Fill in the form that appears:o Application Nameis the app name that appears to users. For this project, use My First App.o Project Nameis the name of your project directory and the name vi

4、sible in Eclipse.o Package Nameis the package namespace for your app (following the same rules as packages in the Java programming language). Your package name must be unique across all packages installed on the Android system. For this reason, its generally best if you use a name that begins with t

5、he 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 Google Play using the com.example namespace.o Build SDKis the platform version against which you will compile your app. By def

6、ault, this is set to the latest version of Android available in your SDK. (It should be Android 4.1 or greater; if you dont have such a version available, you must install one using theSDK Manager). You can still build your app to support older versions, but setting the build target to the latest ve

7、rsion allows you to enable new features and optimize your app for a great user experience on the latest devices.o Minimum Required SDKis the lowest version of Android that your app supports. To support as many devices as possible, you should set this to the lowest version available that allows your

8、app to provide its core feature set. If any feature of your app is possible only on newer versions of Android and its not critical to the apps core feature set, you can enable the feature only when running on the versions that support it.Leave this set to the default value for this project.2. ClickN

9、ext.3. The following screen provides tools to help you create a launcher icon for your app.You can customize an icon in several ways and the tool generates an icon for all screen densities. Before you publish your app, you should be sure your icon meets the specifications defined in theIconographyde

10、sign guide.ClickNext.4. Now you can select an activity template from which to begin building your app.For this project, selectBlankActivityand clickNext.5. Leave all the details for the activity in their default state and clickFinish.Your Android project is now set up with some default files and you

11、re ready to begin building the app. Continue to thenext lesson.Create a Project with Command Line ToolsIf youre not using the Eclipse IDE with the ADT plugin, you can instead create your project using the SDK tools from a command line:1. Change directories into the Android SDKstools/path.2. Execute:

12、android list targetsThis prints a list of the available Android platforms that youve downloaded for your SDK. Find the platform against which you want to compile your app. Make a note of the target id. We recommend that you select the highest version possible. You can still build your app to support

13、 older versions, but setting the build target to the latest version allows you to optimize your app for the latest devices.If you dont see any targets listed, you need to install some using the Android SDK Manager tool. SeeAdding Platforms and Packages.3. Execute:android create project -target -name

14、 MyFirstApp -path /MyFirstApp -activity MainActivity -package com.example.myfirstapp Replacewith an id from the list of targets (from the previous step) and replacewith the location in which you want to save your Android projects.Your Android project is now set up with several default configurations

15、 and youre ready to begin building the app. Continue to thenext lesson.Tip:Add theplatform-tools/as well as thetools/directory to yourPATHenvironment variable.Running Your AppIf you followed theprevious lessonto create an Android project, it includes a default set of Hello World source files that al

16、low you to immediately run the app.How you run your app depends on two things: whether you have a real Android-powered device and whether youre using Eclipse. This lesson shows you how to install and run your app on a real device and on the Android emulator, and in both cases with either Eclipse or

17、the command line tools.Before you run your app, you should be aware of a few directories and files in the Android project:AndroidManifest.xmlThemanifest filedescribes the fundamental characteristics of the app and defines each of its components. Youll learn about various declarations in this file as

18、 you read more training classes.src/Directory for your apps main source files. By default, it includes anActivityclass that runs when your app is launched using the app icon.res/Contains several sub-directories forapp resources. Here are just a few:drawable-hdpi/Directory for drawable objects (such

19、as bitmaps) that are designed for high-density (hdpi) screens. Other drawable directories contain assets designed for other screen densities.layout/Directory for files that define your apps user interface.values/Directory for other various XML files that contain a collection of resources, such as st

20、ring and color definitions.When you build and run the default Android app, the defaultActivityclass starts and loads a layout file that says Hello World. The result is nothing exciting, but its important that you understand how to run your app before you start developing.Run on a Real DeviceIf you h

21、ave a real Android-powered device, heres how you can install and run your app:1. Plug in your device to your development machine with a USB cable. If youre developing on Windows, you might need to install the appropriate USB driver for your device. For help installing drivers, see theOEM USB Drivers

22、document.2. Ensure thatUSB debuggingis enabled in the device Settings (open Settings and navitage toApplications Developmenton most devices, or clickDeveloper optionson Android 4.0 and higher).To run the app from Eclipse, open one of your projects files and click Runfrom the toolbar. Eclipse install

23、s the app on your connected device and starts it.Or to run your app from a command line:1. ant debugChange directories to the root of your Android project and execute:2. adb install bin/MyFirstApp-debug.apkMake sure the Android SDKplatform-tools/directory is included in yourPATHenvironment variable,

24、 then execute:3. On your device, locateMyFirstActivityand open it.Thats how you build and run your Android app on a device! To start developing, continue to thenext lesson.Run on the EmulatorWhether youre using Eclipse or the command line, to run your app on the emulator you need to first create an

25、Android Virtual Device(AVD). An AVD is a device configuration for the Android emulator that allows you to model different devices.Figure 1.The AVD Manager showing a few virtual devices.To create an AVD:1. Launch the Android Virtual Device Manager:a. In Eclipse, click Android Virtual Device Managerfr

26、om the toolbar.b. android avdFrom the command line, change directories to/tools/and execute:2. In theAndroid Virtual Device Managerpanel, clickNew.3. Fill in the details for the AVD. Give it a name, a platform target, an SD card size, and a skin (HVGA is default).4. ClickCreate AVD.5. Select the new

27、 AVD from theAndroid Virtual Device Managerand clickStart.6. After the emulator boots up, unlock the emulator screen.To run the app from Eclipse, open one of your projects files and click Runfrom the toolbar. Eclipse installs the app on your AVD and starts it.Or to run your app from the command line

28、:1. Change directories to the root of your Android project and execute:ant debug2. Make sure the Android SDKplatform-tools/directory is included in yourPATHenvironment variable, then execute:adb install bin/MyFirstApp-debug.apk3. On the emulator, locateMyFirstActivityand open it.Thats how you build

29、and run your Android app on the emulator! To start developing, continue to thenext lesson.Building a Simple User InterfaceAlternative LayoutsDeclaring your UI layout in XML rather than runtime code is useful for several reasons, but its especially important so you can create different layouts for di

30、fferent screen sizes. For example, you can create two versions of a layout and tell the system to use one on small screens and the other on large screens. For more information, see the class aboutSupporting Different Devices.The graphical user interface for an Android app is built using a hierarchy

31、ofViewandViewGroupobjects.Viewobjects are usually UI widgets such asbuttonsortext fieldsandViewGroupobjects are invisible view containers that define how the child views are laid out, such as in a grid or a vertical list.Android provides an XML vocabulary that corresponds to the subclasses ofViewandViewGroupso you can define your UI in XML using a hierarchy of UI elements.Figure 1.Illustration of howViewGroupobjects form branches in the layout and contain otherViewobjects.In this lesson, youll create a layout in XML that includes a text field and a button. In t

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1