Last week, Android's official blog released a statement: Google will end its development of Eclipse+adt and stop support at the end of the year, shifting its focus completely to Android Studio. For many Android developers who use Eclipse, they must accept a new IDE. According to Google, Android Studio is very smart and powerful. Share some of the basic experiences of Android studio here.
Reference Source: Time to Migrate Android Projects to Android Studio
Xiao Ling
Translation: Yushulx
Android Studio Download Installation
This everybody knows, use VPN to fix. Complete installation package can be used Thunderbolt offline, will be relatively fast.
Eclipse ADT Project imported into Android Studio
The steps are simple:
File->new->new Projects
Set the code path.
Finally determined
This time the compilation does not pass completely, there will be some errors. For example, the output path needs to be set. Android Studio will be prompted, all fix is ready
Handy shortcuts in Android studio
When Android studio opens, it automatically jumps out some tips to learn the following shortcuts:
Ctrl+alt+shift+n: Global search for any symbol
CTRL + N: Global search for any class
Ctrl+shift+a: Find menu commands and toolbar functions
ALT+F7: Finding the use of variables
Ctrl+alt+shift+s: Open Project Properties
Ctrl+shift+enter: You can automatically add curly braces after entering parentheses
Alt+enter: Auto Fix Error
Ctrl+alt+t: Automatically add some code templates, such as Try/catch
Shift+shift: Global search for various files, classes, variables, etc.
Create a simple project
Take a look at some of the differences between Android studio and Eclipse
Project Creation Wizard
file->new->new Project :
Android Studio will help you choose your target device
There are various activity templates to choose from.
If you want to learn sample, you can import it from GitHub.
Build Android Apps with Gradle
Android Studio uses Gradle to build Android projects.
Androidmanifest.xml is not the same as in Eclipse. The SDK versions are transferred to the Build.gradle file:
apply plugin: ' Com.android.application ' android { compilesdkversion 22 buildToolsVersion "22.0.1" defaultconfig { applicationId "Dynamsoft.com.demo" minSdkVersion 19 targetsdkversion 22 versioncode 1 versionName "1.0" } buildtypes { release { minifyEnabled false proguardfiles getdefaultproguardfile (' proguard-android.txt '), ' Proguard-rules.pro ' &Nbsp; } }} dependencies { compile filetree (dir: ' Libs ', include: [' *.jar ']) compile ' Com.android.support:appcompat-v7:22.2.0 '}
Android UI Editor
The UI editor for Android Studio is very handy and can be previewed in real time:
Create a custom view
Creating a custom view in Eclipse is cumbersome and error-prone. In Android Studio, it's completely auto-created. Just click on the menu New, UI Component, Custom View .
The corresponding file is automatically generated.
How to generate a signature apk
The person who wants to publish the app needs to sign the APK. Android Studio is also very simple.
How to add dependencies in Android Studio
In Android engineering we often need to use third-party libraries or source code. 3 ways to add dependencies are available in Android Studio. Using ctrl+alt+shift+s to open Project properties and select dependencies, you can see:
Library dependency is adding dependencies from the MAVEN repository
File dependency is the addition of a code file or jar file
Module dependency is to create a module (e.g. zxing source code) in the project and add it in
Use zxing to create a simple QR code scanning application
Get the source code from GitHub first:
git clone https://github.com/zxing/zxing
Create a module:
Import zxing Source:
Add Module dependency:
To create a simple layout:
<relativelayout xmlns:android= "Http://schemas.android.com/apk/res/android" xmlns:tools= "Http://schemas.android.com/tools" android:layout_width= "Match_parent" android:layout_height= "Match_parent" android:paddingleft= "@dimen/activity_horizontal_margin" android:paddingright= "@dimen/activity_horizontal_margin" android: paddingtop= "@dimen/activity_vertical_margin" android:paddingbottom= "@dimen/activity_ Vertical_margin " tools:context=". Mainactivityfragment "> <EditText android:layout_width= "Fill_parent" android:layout_height= "Wrap_content" android:id= "@+id/edittext" android:layout_alignparentstart= "true" /> &Lt Button android:layout_width= "Wrap_content" android:layout_height= "Wrap_content" android:layout_below= "@id/edittext" android:text= " Generate qrcode " android:id=" @+id/barcode_button " / > <imageview android:layout_width= "400DP" android:layout_height= "400DP" android:layout_below= "@id/barcode_button" android:id= "@+id/barcode" android:background= "@color/abc_ Search_url_text_normal "/></relativelayout>
Use qrcodewriter to generate QR code:
Public void onclick (VIEW&NBSP;V) { String content = Medittext.gettext (). toString (); qrcodewriter write = new Qrcodewriter (); try { int Width = mimageview.getwidth (); int height = mimageview.getheight (); bitmatrix bitmatrix = write.encode (content, barcodeformat.qr_code, width, height); bitmap bitmap = bitmap.createbitmap (width, height, Bitmap.Config.ARGB_8888); for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { bitmap.setpixel (I, j, bitmatrix.get (i, j) ? Color.BLACK : color.white); } } mimageview.setimagebitmap (bitmap); } catch (writerexception e) { e.printstacktrace (); }}
Operating effect:
Android Studio Compare Eclipse
And Eclipse, Android Studio is a brand new experience. Android Studio occasionally appears stuck in use, but features like Google say are very powerful, including a variety of useful shortcuts, code intelligence tips, code analysis and so on. Once you're familiar with the operation, you'll never want to go back to eclipse at all.
Google will focus on Android Studio and abandon Eclipse+adt