Android Studio入门指南
Android-Studio开发初学者指南

Android Studio开发初学者指南Android开发有多种方式,但迄今为止最正式和强大的是使用Android Studio开发。
Android Studio是Android平台的官方IDE(集成开发环境),由谷歌开发。
Android Studio于2013年在谷歌I/O大会上首次发布,并于2014年在各种beta版本后向公众发布。
在Android Studio发布之前,Android开发主要是通过Eclipse IDE进行的,Eclipse IDE是一种更通用的Java IDE,支持更多其他编程语言。
对于初学者来说,用Android Studio开发有很多东西要学习,而且很多信息——甚至是通过官方渠道——要么过时了,要么太过晦涩难懂。
本文试图较为详细地解释Android Studio的功能,并介绍基本功能,试着让开发都尽可能简单,希望能成为开发Android的第一步。
一、概念对于没有编程经验的人可能仍然想知道Android Studio在开发APP时的角色是什么…到底什么是IDE ?作为一个IDE(集成开发环境), Android Studio的工作就是为你开发APP提供界面接口,并处理大量复杂的文件管理。
Android Studio的编程语言是Java,需要在计算机上安装JDK。
Android Studio是你编写、编辑和保存项目和文件的环境。
Android Studio允许您访问Android SDK(Software Development Kit软件开发工具包)。
可以把Android SDK看作是Java的扩展库,能够让你开发的APP在Android设备上平稳运行,并利用本机硬件。
开发APP需要Java 和Android SDK,才能让APP在Android上运行,而Android Studio的工作就是将它们组合在一起。
同时,Android Studio还允许您通过模拟器或连接到电脑的硬件(手机、平板电脑等设备)运行代码。
Android Studio 快速上手指南说明书

Table of ContentsAbout1 Chapter 1: Getting started with android-studio2 Remarks2 Versions2 Examples3 Installation or Setup3 Windows3 Mac4 Linux4 Notes5 Problem with downloading5 Useful shortcuts5 Navigation Shortcuts5 Navigation Shortcuts - Mac OS X6 Programming Shortcuts6 Preview Different Screen Size (Devices) and Orientations61. Preview Different Devices62. Switching Orientation8 Use your favorite tool shortcuts in Android Studio10 Chapter 2: Android Studio optimization11 Parameters11 Examples11 Customize the VM Option11 Windows:11 Mac:11 Linux:11 Default setting for Android Studio 64-bit11 Optimized Setting12 Chapter 3: Android Studio Tips and Tricks13Examples13 Emulator for testing13 Custom Live Template13 Example :13 To achieve this purpose , you should add a custom Live Template:14 Use Custom Code Styles, Share with other Team Members and Auto Format with Shortcut17 Chapter 4: Android Studio updates20 Examples20 Updating Android Studio in Ubuntu20 Android Studio update channels20 Overview20 Selecting an Update Channel20 Credits22AboutYou can share this PDF with anyone you feel could benefit from it, downloaded the latest version from: android-studioIt is an unofficial and free android-studio ebook created for educational purposes. All the content is extracted from Stack Overflow Documentation, which is written by many hardworking individuals at Stack Overflow. It is neither affiliated with Stack Overflow nor official android-studio.The content is released under Creative Commons BY-SA, and the list of contributors to each chapter are provided in the credits section at the end of this book. Images may be copyright of their respective owners unless otherwise specified. All trademarks and registered trademarks are the property of their respective company owners.Use the content presented in this book at your own risk; it is not guaranteed to be correct nor accurate, please send your feedback and corrections to ********************Chapter 1: Getting started with android-studioRemarksAndroid Studio is the official IDE by Google for Android app development, based on IntelliJ IDEA.[1]It utilizes a Gradle-based build system through the Android Plugin for Gradle. [2]VersionsExamplesInstallation or SetupWindowsVerify that you have the correct JDK. You can check it by opening command prompt (press windows key and write cmd ). In the command prompt type javac -version , this will show the current version of JDK installed on your matching or an error* if Java is missing. If the JDK is not available or the version is lower than 1.8, download the Java SE Development Kit 8.1. Download the latest Android Studio .2. Launch the downloaded .exe file.3. Follow the wizard to install Android Studio4. After installation completes, open Android Studio from the shortcut that has been made on Desktop during the installation process.5.When you open Android Studio for first time, it may ask you to copy your previous settings,6.but as it is your first time you can simply choose not to copy anything.Then Android Studio ask to download the required API's to develop Android apps. Download7.those, after downloading the IDE will open and you will be able to write your first app.Mac1.Verify that you have the correct JDK. You can check it by opening terminal (press command + space and write terminal). In the command line type javac -version, this will show thecurrent version of JDK installed on your matching or an error* if Java is missing. If the JDK is not available or the version is lower than 1.8, download the Java SE Development Kit 8. **2.Download the latest Android Studio.3.Launch the downloaded .dmg file.4.Drag and drop Android Studio into the Applications folder, then launch Android Studio.5.Open Android Studio.6.When you open Android Studio for first time, it may ask you to copy your previous settings, but as it is your first time you can simply choose not to copy anything.7.Then Android Studio ask to download the required API's to develop Android apps. Download those, after downloading the IDE will open and you will be able to write your first app.Linux1.Verify that you have the correct JDK. You can check it by opening terminal (press command + space and write terminal). In the command line type javac -version, this will show the current version of JDK installed on your matching or an error* if Java is missing. If the JDK is not available or the version is lower than 1.8, download the Java SE Development Kit 8. **2.Download the latest Android Studio.3.Unzip/extract Android Studio in a specific folder.4.Open terminal and go the path where you have extracted the Android Studio. (Then, use cd command to go inside the Android Studio folder.) After going in we need to go inside binfolder so again,use command cd bin and enter.5.Now we need to change the mod of our required file i.e studio.sh to do so enter command sudo chmod 777 -R studio.sh , press enter and write your password(if any) and enter. (Also you can see the list of files present inside bin by command ls.).6.After changing mod we just have to run the .studio.sh file to do so enter command./studio.shWhen you run above command Android Studio launch for first time, it may ask you to copy7.your previous settings, but as it is your first time you can simply choose not to copy anything.8.Then Android Studio ask to download the required API's to develop Android apps. Download those, after downloading the IDE will open and you will be able to write your first app.You may encounter "unable to run mksdcard SDK tool" when you are installing androidstudio in 64 bit ubuntu os because studio requires some 32 binaries. To overcome thiserror finish and close Android Studio & go to terminal and run sudo apt-get installlib32z1 lib32ncurses5 lib32bz2-1.0 lib32stdc++6. Once installation is completed forthese binaries again go back to step 6 and resume installation process.Notes•If you have already installed JDK and still getting then make sure you have set JAVA_HOME in your System Variables. You can check this answer on how to setup one.There are, however, known stability issues in Android Studio on Mac when using JDK 1.8.•Until these issues are resolved, you can improve stability by downgrading your JDK to an older version (but no lower than JDK 1.6).•While the Android Studio download completes, verify which version of the JDK you have: open a command line and type javac -version. If the JDK is not available or the version is lower than 1.8, download the Java SE Development Kit 8.If you are running a 64-bit version of Ubuntu, you need to install some 32-bit libraries with •the following commands:sudo dpkg --add-architecture i386sudo apt-get updatesudo apt-get install lib32z1 lib32ncurses5 libbz2-1.0:i386 lib32stdc++6•If you are running 64-bit Fedora, the command is:sudo yum install zlib.i686 ncurses-libs.i686 bzip2-libs.i686Problem with downloadingIf you would face any issue like message that your system is not compatible with Android •Studio (it may happen when you're using web browser different than Chrome) downloadAndroid Studio from: /That's it!Useful shortcutsNavigation ShortcutsGo to class Ctrl+NGo to file Ctrl + Shift + NNavigate open tabs ALT + Left-Arrow; ALT + Right-Arrow Lookup recent files CTRL + EGo to line CTRL + GNavigate to last edit location CTRL + SHIFT + BACKSPACEGo to declaration CTRL + BGo to implementation CTRL + ALT + BGo to source F4Go to super Class CTRL + UShow Call hierarchy Ctrl + Alt + HSearch in path/project CTRL + SHIFT + FNavigation Shortcuts - Mac OS XGo to line number CMD + LProgramming ShortcutsReformat code CTRL + ALT + LOptimize imports CTRL + ALT + OCode Completion CTRL + SPACEIssue quick fix ALT + ENTERSurround code block CTRL + ALT + TRename and refactor Shift + F6Line Comment or Uncomment CTRL + /Block Comment or Uncomment CTRL + SHIFT + /Go to previous/next method ALT + UP/DOWNShow parameters for method CTRL + PQuick documentation lookup CTRL + QProject Alt+1Version Control Alt+9Run Shift+F10Debug Shift+F9Android Monitor Alt+6Return to Editor EscHide All Tool Windows CTRL +Shift+F12Auto generate code(constructor,getter/setter etc) Alt+insertCode completion CTRL+SpaceSmart code completion(by expected type) CTRL+Shift+SpaceShow quick fix CTRL+EnterDuplicate Line Ctrl+DDelete Line Ctrl+YPreview Different Screen Size (Devices) and Orientations 2.1.31. Preview Different DevicesThere is a preview panel at the right of the android studio. In thispanel there is a button with device name with which you are previewing the UI of your app like this .Click on small dropdown indicator of this and a floating panel will appear with all the predefined devices. You can select any of them to preview your App UI with different devices mentioning their screen sizes.Check this image2. Switching OrientationAnd Next to this button there is another button likeClicking to its dropdown a floating panel will appear with some options like portrait , landscape etc. select one of them to preview in different orientations.Check the this image2.2.0The option to preview all screen sizes is not available from Android Studio 2.2 Beta 2. However, you can resize the preview screen to see how your layout would look on different screen sizes, as shown in the attached.Check: Android Studio 2.2 Preview all screen sizes missingUse your favorite tool shortcuts in Android StudioGo to File > Settings > Keymap and select the Keymaps option from:•Mac OS X•EmacsVisual Studio••Eclise•Netbeans•Jbuilderand others, to map the shortcuts to the wanted tool ones.Read Getting started with android-studio online: https:///android-studio/topic/830/getting-started-with-android-studioChapter 2: Android Studio optimization ParametersExamplesCustomize the VM OptionYou can override the default vmoptions with your own personal settings by choosing Help > Edit Custom VM Options from the Android Studio toolbar. This will create a local copy which you are free to edit.Alternatively, you can edit the default vmoptions directly using the paths given below. Note that this method is not recommended, and your changes may be overwritten when updating Android Studio.Windows:%USERPROFILE%\.{FOLDER_NAME}\studio.exe.vmoptions and/or%USERPROFILE%\.{FOLDER_NAME}\studio64.exe.vmoptions%USERPROFILE%\.{FOLDER_NAME}\idea.propertiesMac:~/Library/Preferences/{FOLDER_NAME}/studio.vmoptions~/Library/Preferences/{FOLDER_NAME}/idea.propertiesLinux:~/.{FOLDER_NAME}/studio.vmoptions~/.{FOLDER_NAME}/studio64.vmoptions~/.{FOLDER_NAME}/idea.propertiesDefault setting for Android Studio 64-bit-Xms128m-Xmx750m-XX:MaxPermSize=350m-XX:ReservedCodeCacheSize=96m-eaeCanonCaches=false.preferIPv4Stack=true-Djna.nosys=true-Djna.boot.library.path=-Djna.debug_load=true-Djna.debug_load.jna=true-Djsse.enableSNIExtension=false-XX:+UseCodeCacheFlushing-XX:+UseConcMarkSweepGC-XX:SoftRefLRUPolicyMSPerMB=50-Didea.platform.prefix=AndroidStudio-Didea.paths.selector=AndroidStudioOptimized Setting-Xms1024m-Xmx4096m-XX:MaxPermSize=1024m-XX:ReservedCodeCacheSize=256m-eaeCanonCaches=false.preferIPv4Stack=true-Djna.nosys=true-Djna.boot.library.path=-Djna.debug_load=true-Djna.debug_load.jna=true-Djsse.enableSNIExtension=false-XX:+UseCodeCacheFlushing-XX:+UseConcMarkSweepGC-XX:SoftRefLRUPolicyMSPerMB=50-Didea.platform.prefix=AndroidStudio-Didea.paths.selector=AndroidStudioRead Android Studio optimization online: https:///android-studio/topic/3247/android-studio-optimizationChapter 3: Android Studio Tips and Tricks ExamplesEmulator for testingIf there are no specific needs, choose x86_64 system images with Google APIs to create the emulator.It works way faster than armeabi-v7a on intel x86 x64 based computers.There are some SDK libraries compiled and designed with ARM architecture.If you try to install them on Intel based emulators you'll get an error message saying "INSTALL_FAILED_NO_MATCHING_ABIS"You can go for a 3rd party emulator like Genymotion or Visual Studio's standalone Android Emulator on such occasions.Custom Live TemplateExample :To achieve this purpose , you should add a custom Live Template:Open Settings [Ctrl + Alt + S ]1. Type "Live Templates" in the Top-Left search bar.2. Click the + to add a "Template Group" and type a group name(eg: MyTemplate) to continue3.Choose your custom template group(eg: MyTemplate), then click + and choose "Live Template".4. I will take "say" for example:say -> startActivity(new Intent($from$.this,$to$.class));5. Type the key that you want to simplify in "Abbreviation" (eg: say),and type the statement in the "Template Text" (eg :startActivity(new Intent($from$.this,$to$.class));)6.Click the "define" in the Left-Bottom and choose the situation(eg: Java)7.Click the "Edit variables",define the expression.(see detail:Edit Template Variables Dialog)8.9.Click "OK" and "Apply". And try to type "say" in your editor.Use Custom Code Styles, Share with other Team Members and Auto Format with ShortcutIt's possible to have your own custom code styles, share them with other team members and use a shortcut to auto format the code in a file.To create your own custom code style, go to: Preferences -> Editor -> Code StyleThere are some general code style settings here. You can also select the language (Java for Android) and set the parameters as you see fit. There's a lot of settings.Once you've done this, save your code style. This is just for safe keeping.Once you've saved it, select "Copy to Project" from the "Manage" dialog. You will be asked whether you want to switch to this created scheme. Answer yes.Once this is done, close the Code Style preferences dialog.Now, verify that your code style settings have been saved in: .idea/codeStyleSettings.xmlEnsure that this file is not ignored in your version control system so that you can share it with your teammates.Once your teammates have this file, they should also have the same settings.Now, when editing a file, you can format the code by selecting:Code -> Reformat CodeShortcuts for Reformat Code (taken from this answer - see answer for details on resolving issues with shortcut in Ubuntu):WinCtrl + Alt + LLinux:Ctrl + Shift + Alt + LMac:Option + Command + LWhen you perform a code reformat, a small dialog should popup informing you of the changes made. You can click "Show" in this dialog to bring up the "Reformat File Dialog".You can also bring up this dialog from the Code menu and its corresponding shortcut.Be warned that "Only VCS changed text" doesn't always work depending on how the code has been edited (it may ignore a rule if part of the code has not been edited).You can also select text and show the reformat code dialog to format only the select text.Read Android Studio Tips and Tricks online: https:///android-studio/topic/2228/android-studio-tips-and-tricksChapter 4: Android Studio updatesExamplesUpdating Android Studio in UbuntuIf you are able to download an update of Android Studio, but after it restarts nothing happens, check out the following example:After the patch was downloaded and Android Studio closed, open the terminal1.2.Go to your android studio folder, e.g. cd ~/android-studio3.Go to bin subfolder: cd bin4.Make sure your studio.sh file has run permissions: chmod +x studio.sh5.Run Android Studio from here: ./studio.shAfter that Android Studio will find the patch and install it. Then you may close Android Studio and run it the regular way (whatever way you prefer, I run it from Launcher pad).Android Studio update channelsOverviewAndroid Studio's built-in update mechanism can be set to receive updates through any one of these four channels:•Canary: Bleeding edge, released about weekly. These are early previews released in order to obtain real-world feedback during development. The canary channel will always have the latest build, including updates to beta or stable releases. We recommend running canary builds side-by-side with a beta or stable installation.Dev: Canary builds after a full round of internal testing get promoted into the Dev Channel.••Beta: Release candidates based on stable canary builds, released and updated to obtain feedback prior to the stable release. The beta channel will be updated with new stable builds until a new canary build goes to beta.•Stable: The official stable release, as available from the Android Developer site.Download the full installations of the build offered in each of these channels: Canary, Dev, Beta, Stable.Alternatively, you can build it yourself, following the instructions in Build Overview.Selecting an Update ChannelTo select the update channel for an Android Studio installation go through:File > Settings > System Settings > Updatesand choose the appropriate channel on which to check for updates:When an update is available, you'll be prompted by the IDE:Selecting update will display the update information dialog with details information on the patch available, its size and its channel:Read Android Studio updates online: https:///android-studio/topic/1998/android-studio-updatesCredits。
学会使用AndroidStudio进行Android应用开发和调试

学会使用AndroidStudio进行Android应用开发和调试第一章:开发环境配置和项目创建Android Studio作为Android应用开发的主要工具,我们首先需要进行环境配置和项目创建。
1.1 下载和安装Android Studio首先,我们需要从官网下载Android Studio,并按照提示进行安装。
1.2 配置JDKAndroid Studio需要依赖Java Development Kit(JDK),因此我们需要确保正确配置JDK的路径,并将其添加到系统环境变量中。
1.3 创建新项目打开Android Studio后,点击“Start a new Android Studio project”,然后按照向导的提示填写项目名称、包名、项目类型等信息,最后点击“Finish”即可创建新项目。
第二章:界面设计和布局在Android应用开发中,界面设计和布局是非常重要的一部分,我们需要学会使用Android Studio自带的布局编辑器进行界面设计。
2.1 布局编辑器使用介绍Android Studio的布局编辑器可以帮助我们可视化地设计应用界面,并生成对应的XML布局文件。
通过拖拽和调整组件的位置和大小,我们可以轻松创建复杂的界面布局。
2.2 布局类型和组件Android Studio提供了多种布局类型(如线性布局、相对布局等),每种布局类型都有不同的特点和适用场景。
同时,Android Studio也提供了丰富的组件供我们使用,如按钮、文本框、图片等。
2.3 XML布局文件编辑在布局编辑器生成的XML布局文件中,我们可以手动编辑和调整布局,添加自定义属性和事件等。
掌握XML布局文件的编写能力,对于实现更复杂的界面布局和逻辑处理非常有帮助。
第三章:Activity和生命周期管理Activity是Android应用开发中的核心概念之一,我们需要了解Activity的基本用法和生命周期管理。
轻松上手使用AndroidStudio进行应用开发

轻松上手使用AndroidStudio进行应用开发第一章:AndroidStudio简介与安装AndroidStudio是一款由谷歌公司开发的集成开发环境(IDE),用于轻松开发Android应用程序。
本章将介绍AndroidStudio的功能和特点,并提供安装指南。
1.1 AndroidStudio的功能与特点AndroidStudio提供了丰富的功能和特点,使开发人员能够更轻松地进行应用开发。
首先,AndroidStudio集成了Android开发工具包(SDK),可以直接从IDE中访问和管理所有Android开发工具和资源。
这大大简化了开发流程,提高了开发效率。
其次,AndroidStudio支持快速的应用程序原型设计和界面布局。
通过AndroidStudio的可视化编辑器,开发人员可以轻松创建和调整应用程序的用户界面。
该编辑器还提供了丰富的界面组件库,可以直接拖拽组件到界面上,并设置属性和样式。
另外,AndroidStudio还提供了强大的代码编辑器,支持代码自动完成、语法高亮和错误检查等功能。
开发人员可以在编辑器中编写和调试Java代码,并将其与XML布局文件进行无缝集成。
此外,AndroidStudio还提供了模拟器和真机调试功能,可以在IDE中进行应用程序的测试和调试。
开发人员可以模拟不同的设备和操作系统版本来测试应用程序的兼容性,并实时查看应用程序在不同设备上的运行效果。
1.2 AndroidStudio的安装指南安装AndroidStudio之前,首先需要确保电脑系统满足一些基本要求,如操作系统版本、CPU和内存等。
其次,需要从谷歌官方网站下载最新版本的AndroidStudio安装包。
安装AndroidStudio的具体步骤如下:1. 打开安装包并运行安装程序,按照提示进行安装。
2. 在安装向导中选择要安装的组件。
建议选择默认组件,以确保安装了必要的工具和插件。
3. 设置AndroidSDK的安装路径。
AndroidStudio应用开发入门教学

AndroidStudio应用开发入门教学Android Studio应用开发入门教学第一章:Android Studio的安装和配置1.1 Android Studio的介绍Android Studio是谷歌官方推出的一款专业的Android应用开发工具。
它基于IntelliJ IDEA开发,提供了丰富的功能和工具,能够方便开发人员进行Android应用程序的设计、开发和调试。
1.2 安装Android Studio首先,下载Android Studio安装包并运行安装程序。
按照安装向导的提示,选择安装路径和组件,完成基本安装。
安装完成后,打开Android Studio并进行首次配置。
1.3 配置Android SDKAndroid Studio依赖Android SDK来编译和运行应用程序。
首次打开Android Studio时,会提示配置SDK路径。
点击“Next”按钮,选择安装的SDK目录或者下载最新的SDK版本。
配置完成后,等待SDK的下载和安装。
第二章:新建Android项目2.1 新建Android项目在Android Studio的欢迎界面中,选择“Start a new Android Studio project”选项。
在弹出的新项目向导中,填写应用程序的名称、包名、项目存储位置等信息,并选择最低兼容的Android版本。
2.2 配置应用程序的基本信息在新项目创建完成后,可以通过编辑“AndroidManifest.xml”文件来配置应用程序的基本信息,如应用程序的图标、名称、版本信息等。
同时,也可以配置应用程序的权限和组件,以及清单文件中的其他标签。
第三章:界面设计与布局3.1 用户界面设计原则用户界面设计是Android应用开发的关键步骤之一。
在设计界面时应遵循直观、简洁、一致性和可用性的原则,确保用户能够方便、快速地使用应用程序。
3.2 使用布局容器Android提供了多种布局容器,如线性布局、相对布局、网格布局等,用于控制界面上的组件的排列方式。
如何使用AndroidStudio开发手机应用

如何使用AndroidStudio开发手机应用Android Studio是一款专业的集成开发环境(IDE),专为安卓应用程序的开发而设计。
它提供了一系列的工具和功能,帮助开发者简化开发流程,并提高应用程序的质量和性能。
本文将介绍如何使用Android Studio开发手机应用,并以章节的形式详细讨论各个方面的内容。
第一章:安装与配置在使用Android Studio之前,需要先进行安装和配置。
首先,下载最新版本的Android Studio并按照指示进行安装。
安装完成后,根据需要进行相应的配置,如选择开发工具链和安装必要的SDK版本。
此外,还可以根据个人首选项进行界面和键绑定设置。
第二章:项目创建与结构在Android Studio中创建项目非常简单。
在创建项目时,需要提供应用程序的名称、包名和最低支持的Android版本等信息。
创建项目后,可以看到项目结构视图,其中包含了模块、资源文件、依赖项等。
可以通过拖拽文件或者使用快捷键来创建新的文件、文件夹、布局等。
第三章:界面设计与布局Android Studio提供了强大的界面设计工具,可以通过可视化编辑器来创建和编辑应用程序的布局。
可以使用拖拽的方式添加和调整UI组件,也可以手动修改XML文件来进行布局。
此外,还可以使用约束布局等灵活的布局方式来适应不同的屏幕尺寸和方向。
第四章:代码编写与调试在Android Studio中,可以使用Java或者Kotlin编写应用程序的逻辑和功能代码。
IDE提供了自动完成、代码重构、实时错误检查等功能,大大提高了开发效率。
同时,还可以通过Android Studio内置的模拟器或者连接真实设备进行调试和测试。
IDE还支持断点调试、日志查看等功能,方便开发者定位和修复问题。
第五章:资源管理与国际化Android Studio提供了资源管理工具,可以轻松管理应用程序的图像、音频、文字等资源文件。
可以通过资源管理器来复制、删除、重命名等操作。
Android Studio开发手册

Android Studio开发手册第一章 Android Studio简介及其环境搭建1.1 Android Studio简介1.1.1 Android Studio能做什么谷歌公司的 Android操作系统,作为智能手机等移动设备的平台。
Android Studio是谷歌公司研发的开发基于 Android系统的软件开发工具,也就是开发运行在 Android平台上的 APP,这些应用可以设计为工具、管理、互联网、游戏等等软件。
Android Studio开发的产品不仅可以运行在智能手机上,还可以开发智能穿戴、电视、车载设备的应用。
1.1.2 为什么选择 Android Studio从 Android 操作系统诞生的时候,开发基于 Android 系统的 APP 的平台是 Eclipse,关于Android Studio 相比 Eclipse 的优点网络上讨论很多。
Android Studio作为谷歌在 2013 年为开发者提供的 IDE 环境工具,已经成为了非常强大的 IDE 开发环境。
谷歌也宣布将在年底前中止对其他 IDE 开发环境的支持。
安卓产品经理 Jamal Eason 在声明中写道“谷歌将会全力专注于Android Studio 编译工具的开发和技术支持,中止为 Eclipse 提供官方支持。
包括中止对 Eclipse ADT 插件以及Android Ant 编译系统的支持。
”1.2 Android 系统基本知识用 Android Studio 开发出来的 APP 是运行在 Android 操作系统上的,所以这里概述安卓系统的基本知识是非常必要的。
安卓系统是为移动设备准备的操作系统,已被各大移动设备制造商所采用。
它含有一个 Linux 操作系统和一些中间件,通常,它还带有一系列关键应用,如联系人管理、地图应用、浏览器等等。
安卓由谷歌开发和维护,它是一个开源项目,可以下载它的源代码。
图1-1 Android系统这里把安卓平台按照从下至上顺序分为四层,图中最上面为第四层是应用层,一般的安卓设备都会预装一些应用,所以你有联系人管理、打电话、网络浏览器等应用。
android studio教程

android studio教程Android Studio是一款由Google公司开发的集成开发环境(IDE),专门用于Android应用程序的开发。
它是基于IntelliJ IDEA的客户端Android开发工具。
本教程将向您介绍Android Studio的基本功能和使用方法。
一、安装Android Studio第一步是下载和安装Android Studio。
您可以在官方网站上找到最新版本的Android Studio并进行下载。
下载完成后,双击安装包进行安装。
安装过程很简单,按照提示一步一步进行即可。
安装完成后,启动Android Studio。
二、创建新项目启动Android Studio后,您将看到欢迎界面。
点击“Start a new Android Studio project”按钮,然后按照向导的指引进行项目的创建。
您需要输入项目的名称、包名和项目的存储位置等信息。
选择合适的目标Android版本和项目模板。
最后,点击“Finish”按钮创建项目。
三、项目结构一旦项目创建完成,您将会看到项目的结构。
在左侧的“Project”窗口中,您可以看到项目的文件和文件夹。
在“Gradle Scripts”文件夹下的build.gradle文件中可以配置项目的构建选项。
四、布局文件布局文件是Android应用程序的界面定义。
在“res”目录下的“layout”文件夹中,您可以找到应用程序的布局文件。
通过拖拽和放置视图部件,您可以在布局文件中创建用户界面。
布局文件使用XML语言进行定义,您可以使用各种不同的视图部件和布局管理器。
五、Java代码在“java”文件夹中,您可以找到应用程序的Java代码。
主要的活动(Activity)类位于默认的包名目录下。
您可以使用Java 代码来处理用户交互事件、访问数据库、调用系统服务等。
Android Studio提供了强大的代码编辑和代码补全功能,可以帮助您编写高效和可维护的代码。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
Android Studio入门指南作者:毕小朋日期:2013.8.51.Android Studio简介Android Studio是一个基于IntelliJIDEA的新的Android开发环境。
与Eclipse ADT 插件相似,AndroidStudio提供了集成的Android开发工具用于开发和调试。
除了你期望的IntelliJ的能力,AndroidStudio还提供:·基于Gradle构建的支持。
· Android专属的重构和快速修复。
·捕获性能、易用性、版本兼容性等问题。
·支持ProGuard和应用签名。
·基于模板的向导来创建常见的Android设计和组件。
·丰富的布局编辑器,允许你拖放UI组件并在多个屏幕上的预览布局,等等。
2. 安装Android Studio1. 从上面下载AndroidStudio安装包。
(下载地址:/sdk/installing/studio.html译者注)2. 安装Android Studio和SDK工具:Windows系统:1. 启动下载的EXE文件,android-studio-bundle-<version>.exe。
2. 按照安装向导安装AndroidStudio。
已知问题:在某些Windows系统中,没有找到Java的安装启动程序脚本。
如果你遇到这样的问题,你需要设置一个环境变量,指向正确的位置。
选择“ 开始“菜单]]> 计算机]]> 系统属性]]> 高级系统属性。
然后打开“高级”选项卡]]> 环境变量,并添加新的系统变量JA V A_HOME,指向你的JDK文件夹,例如C:\ Program Files\JA V A\jdk1.7.0_21。
Mac OS X的:3. 打开下载的DMG文件,android-studio-bundle-<version>.dmg。
4. 拖放AndroidStudio到“应用程序”文件夹中。
已知问题:根据您的安全设置,当你试图打开Android Studio时,你可能会看到一个警告说,安装包损坏、应将其移至垃圾桶。
如果发生这种情况,进入系统偏好设置]] ]]> 安全与隐私,在允许下载的应用程序,选择随时随地。
然后再次打开AndroidStudio。
Linux操作系统:5. 为您的应用程序,解压下载的Tar文件,android-studio-bundle-<version>.tgz 到一个合适的位置。
6. 要启动Android Studio,在终端定位到android-studio/bin/目录,并执行studio.sh。
您可能需要添加android-studio/bin/到你的PATH环境变量,这样就可以从任何目录启动Android Studio。
这就可以了!你已经准备好开始用Android Studio开发应用程序了。
注:在Windows和Mac,Android Studio个人工具和其他的SDK包保存应用程序的目录内。
要直接访问这些工具,使用终端导航到应用程序并定位到sdk/目录。
例如:Windows: \Users\<user>\AppData\Local\Android\android-studio\sdk\Mac: /Applications/Android\Studio.app/sdk/对于一些已知的问题,查看/knownissues。
3.Android Studio界面元素3.1 界面简介1.菜单和工具栏:你懂的2.导航条:编辑文件时帮助定位和导航项目中的文件3.状态栏:显示当前项目,Android Studio本身的状态,还有别的一些状态相关的一些信息4.编辑器:你懂的5.工具窗口:辅助类窗口。
Android Studio提供了各式各样的辅助窗口来帮助完成各种任务,如项目管理,代码查找,版本控制等,类似eclipse中VIEW的概念6.工具窗口栏:位于IDEA界面的上下左右各有一个,摆放着工具窗口显示和隐藏的按键3.2 关于菜单和工具条菜单和工具栏包含了Android Studio中的各种有用的命令,如:(1)打开或者隐藏Android Studio中的界面元素,可以使用菜单栏中的VIEW选项(2)当你想执行一个命令,但忘记去哪里找这个命令的时候,Android Studio提供了一个快捷的方式进行定位,按command+Shift+A 可以触发一个命令提示界面,输入你想执行命令的前缀,就会列出跟这个前缀相关的一些命令,选择你需要的执行3.3 关于导航条显示导航条有两种途径:(1)通过VIEW菜单,选择Navigation Bar 选项(2)按Alt+Home.(用该方式打开,导航条显示为浮动形式(windows))关闭导航条也有两种途径(1)通过VIEW菜单,取消选择Navigation Bar 选项(2)当导航条是浮动状态时候,按ESC键(windows)3.4 关于状态栏3.5 关于工具窗口每个工具窗口提供了各种不同的视角和编程任务,一些工具窗口总是可见的,一些工具窗口则必须当相关的插件或者facets被激活的时候才是可见的. 控制工具窗口显示或者隐藏的按键分布在工具窗口条上,显示和隐藏状态通过颜色区分:工具窗口的显示与隐藏是基于工具窗口的摆放组的,每个工具窗口条分为2个组(水平的工具窗口条的左右两边,垂直窗口条的上下两边,可以通过拖坠工具窗口按键来进行摆放组的移动),每个分组只有一个显示的工具窗口,当选择组中的令一个窗口时,会自动关闭该组原先的窗口3.6 操纵工具窗口3.6.1 关闭所有的工具窗口1.通过菜单栏中的Window - Active Tool Window - Hide All Windows2. command+Shift+F12.3.6.2 保存当前的窗口布局:菜单栏Window - Store Current Layout as Default若需要重置窗口布局选择菜单栏Window - Restore Default Layout3.6.3 窗口工具的查看模式(Viewing Modes)工具窗口提供了不同的查看模式,用于控制工具窗口的显示形式和表现方式,帮助使用者快速定位到工具窗口,或者最大化编辑区域1.固定和浮动模式Floating Mode当窗口时固定模式时,若同时窗口的模式还是非停泊模式(docked mode未选中)则窗口会占满它所附着的工具窗口条的长度或者高度(取决于工具窗口条是水平的还是垂直的)当窗口时浮动模式(Floating)时,它可以放在屏幕上的任何位置,当这个窗口处于不活动状态时,若同时窗口时寄托模式(pinned.mode)它会变成半透明状态(透明度取决于Appearancesettings中的透明度设置)2.停靠和脱开模式Docked Mode该模式基于窗口时固定模式(Docked Mode)才起作用在停靠模式,跟这个窗口相邻的界面元素将环绕着该窗口,调整该窗口的大小会自适应调整相邻窗口的大小在脱开模式时。
该窗口会变成最上层的界面元素,会盖住其他的元素与其相交的部分(除开工具窗口,无法盖住其他的工具窗口,不会存在相交部分,当与其他工具窗口相邻时,无法调整该相邻的边界),重设脱开模式的窗口大小不会自适应的调整其他元素的大小。
当一个脱开模式的窗口变为不活动状态时,它会自动隐藏。
3.寄托与非寄托模式Pinned Mode该模式决定了工具窗口变成不活跃状态时是隐藏还是可见。
Pinned 模式下是可见,unpinned 模式下将会自动隐藏。
当然根据别的模式设定有一些例外情况:Undocked 模式的窗口不活跃时,总是被隐藏Floating 模式的窗口不活跃时,将变成半透明4.分离模式Split Mode该模式决定了同一个工具窗口条中有多少个停靠模式(docked)的窗口可以同时显示(1还是2)同时工具窗口依据该模式将依附其上的窗口进行分组,分离模式的为一组,非分离模式的为另一组,任何一个时候每个分组中只有一个窗口是可见的5. 作为标签显示Show View as Tabs该模式用于控制有多个内容层需要展示的窗口以何种形式的方式来选择内容层Tabbed 模式使用标签页形式非标签页形式,则使用下拉列表的方式进行选择:3.6.4 开启和关闭模式的方法开启和关闭该模式可以通过窗口的上下的上下文菜单(右键菜单)或者主菜单栏中Window - Active Tool Window来转换或3.6.5 在工具窗口的快度搜索1.选择所需的工具窗口2.输入你需要查找内容(文件,类,字段等)的名字,当你输入时,搜索域将出现在该窗口上,并显示你输入的字符3.输入完毕时,按ENTER,窗口上符合要求的结果将被显示和选择. 按ESC隐藏搜索域4. Android Studio基本操作4.1 在编辑器中打开文件打开Project内的文件进行编辑的几种方式:1. 在Project窗口中双击需要编辑的文件。
2. 在Project窗口选择需要编辑的文件,按F43. 在Project窗口选择需要编辑的文件,然后右键弹出上下文菜单,选择Jump to Source4. 使用Go To5. 通过导航条,来选择打开文件:备注:如果文件类型已经注册,则直接使用编辑器打开,(可以在Settings 中的File Types查看已经注册的文件类型).如果文件类型是关联到外部程序的,则使用外部程序打开,如(.doc,.chm, .pdf)如果文件类型没有注册的,IDEA会打开一个对话框,让你注册一个新类型,或者使用相关的外部程序打开2.可以使用下面的几种方式外部文件进行编辑(1)通过主菜单File - Open File(2)将外部文件拖到Android Studio编辑器中3.打开最近打开过的文件(1)通过主菜单View - Recent Files(2)快捷键Command+E4.打开最近更改过的文件(1)通过主菜单View - Recently Changed Files(2)快捷键Command+Shift+E4.2. 标签管理/操作1.标签编辑任一时刻打开一个文件,会以标签页的形式在编辑窗口中出现。
该标签页出现在当前活动的标签页的下个位置,并成为新的活动标签页,当编辑窗口的标签页达到上限时,它会根据标签页关闭的优先策略来关闭掉别的标签页。
当关闭活动的标签页时。
会根据活动标签页选取策略来选择下一个活动标签页签页关闭的优先策略有两种:没有被修改的文件标签页优先被关闭使用的最少文件标签页优先被关闭标签页选取策略有三种:靠近被关闭的活动标签页的左侧标签页靠近被关闭的活动标签页的右侧标签页使用得最频繁的标签页设置这些策略:Preference->Editor->Editor Tabs2.标签操作路径1:通过Window - Editor Tabs 进行操作路径2:在tab上右击,可调出操作菜单3.在标签页间进行切换4.使用Switcher功能control+Tab 项目文件之间切换control+Shift+Tab 工具之间的切换5.在使用过的标签页中前进和后退command+option+Left(后退),command+option+Right(前进)6.拆卸编辑标签页IDEA支持拆卸编辑标签页,将它挪成一个独立的窗口显示。