The most comprehensive use of Android studio tutorials

Source: Internet
Author: User
Tags new set

The most comprehensive use of Android studio tutorials

Android Studio is an IDE (integrated development environment) that has not been available for a long time, and is now being distributed free of charge to Google and Android developers. Android Studio is based on IntelliJ idea, which is also a pretty good set of Android development environments. In today's article, we'll work together to learn how to create a new Android project while giving full play to the benefits of the features offered by Android Studio.

1. Project Settings

Before you start the world of Android studio, you first need to click here to download and install. Please note that you must install JDK 6 or later in advance. If you are in a Windows system environment, start the. exe file first, and then follow the instructions in the Installation Wizard to complete the steps. If you are using an OS X system, first double-click the boot disk image, and then drag and drop Android studio into your application folder.

After successful completion of the above steps, then everyone's development environment should have been correctly set. Next, we're ready to use Android Studio to create our first Android app. When you start Android Studio for the first time, you should see the software's Welcome screen, which also offers some options to guide us through the first step of developing Android apps.

In today's tutorial, we will select the new Project option. But if you want to convert existing projects in other environments, such as Eclipse, into an Android studio project, you can also choose Import Project. Android Studio is able to convert an Eclipse project into an Android studio project and provide users with the necessary configuration files in the project.

If you click Open Project in the list of options, you can open a project that has been created using Android Studio or IntelliJ idea. You can check the copy of a project under version control if you choose Check out from version control (versioning check). In this way, we can base our existing projects and quickly build new targeted versions.

Since we need to start from scratch, this is where you select New project. You will then see a list of options designed to configure our new project. In today's tutorial, we will create a simple application that is designed to demonstrate some of the most important features of Android studio. I believe that everyone, like me, would think that the name "HelloWorld" is best suited to the new project that was developed this time.

As you can see in the above picture, I named my application HelloWorld and set the module name for it. If you are not familiar with IntelliJ idea, you may not know what the module is. A module is actually a standalone unit of functionality that can be compiled, run, tested, and debugged. The module contains source code, compilation scripts, and other components for specific tasks.

When you create a new project, you can also set the package name for the project. By default, Android studio sets the last element of the project package name to the module name, but you can make any changes to it if you want.

Other settings include where the item is saved on the device, the minimum and recommended SDK, the SDK used to compile the project, and the project theme. You can also ask Android studio to create an activity class, customize a startup icon for it, or set whether the project supports GridLayout, fragments, Navigation drawer, or action bar.

Here we do not create custom icons for our own applications, so you can cancel the check box for the "Create custom Launch Icon" item that is currently selected. Click "Next" to proceed with other project setup steps.

Since we checked the "Create activity" item in the previous steps, the navigation will ask you to configure the activity class that we created for Android studio.

Since we will start with the blank activity class, you can click "Next" to perform the following steps of the setup process. Here you need to name the activity class, the main layout, and the fragment layout. You can also set the navigation type, which we set as "None" in today's sample project. The following shows what our setup scheme looks like.

After clicking "Finish", you will see the Android studio user interface as shown. The left side of the window is Project Explorer and the right side is the workspace. Once you've set up your project in Android Studio, we can now look at the key features in Android Studio one by one.

2. Android Virtual Appliance

The so-called Android virtual device-or simply avd---is a set of simulator configurations that allows you to set the Android device model that matches the actual situation. This makes it easier for developers to run and test applications on a variety of device platforms. With the support of the Android virtual device feature, you can specify the hardware and software combinations that need to be emulated for the Android emulator.

The preferred way to create an Android virtual device is through the AVD Manager. You can select Android〉avd Manager in the Tools menu of the Android Studio user interface.

If you have previously set up your development environment correctly, the interface for Android virtual Device Manager should look like the following.

To create a new AVD, we need to click on "New ..." on the right, set the name for the AVD and configure the virtual appliance as shown. Finally click "OK" to create your first set of AVD.

To use the AVD that we just created, you first need to select it in the list of AVD managers and then click "Start ..." on the right side of the window. If everyone's AVD is set up correctly, then the Android emulator should look like this after booting.

Now that the Android emulator has started and started running, it's time to start our application. Choose Run ' HelloWorld ' in the ' Run ' menu--yes, it's as simple as running the app in the Android emulator.

3. Real-time layouts (live layout)

The live layout feature in Android Studio allows you to directly preview your app's user interface without having to run your application in a device or simulator. Real-time layout is an extremely powerful tool that can help developers save a lot of time. With the help of real-time layouts, the task of viewing the application user interface becomes easy and fast.

To use the live layout, we need to double-click the corresponding XML layout file and select the "Text" tab below the workspace. Next, select the "Preview" tab on the right side of the workspace to preview the current layout. Any changes we make to the XML layout are reflected directly in the Preview window on the right. You can look at the following to get a deeper understanding of this feature.

The real-time layout feature gives us a number of notable advantages. For example, you can choose an option from the first menu in the preview panel to make adjustments to the XML layout you are currently using. For example, you can create different portrait and landscape views separately, and Android Studio will assume the task of creating the necessary folders and files.

The second menu in the preview panel allows you to change the size of the device displayed in the preview panel. The third menu function is to adjust the orientation of the device in the preview panel, so that we can more easily see the effects and themes of the same set of layouts in different display modes (portrait and Landscape).

The fourth menu in the preview panel allows us to easily access the individual fragments used by the activity or layout. The preview panel also allows you to change the language used in the live layout to easily preview the display of different languages in the layout scheme. The function of the rightmost menu is to adjust the API version.

The preview panel also contains a number of controls, such as zooming the layout, re-preview the panel, or intercepting the current screen.

4. Templates

Android Studio also provides developers with a variety of template options, which greatly increases development speed. These templates can automatically create activity and the necessary XML files. You can also use these templates to create a more basic Android application and run it in a physical device or simulator.

In Android Studio, we can create a corresponding template together when we create a new activity. Right-click on "Package name" in the project browser on the left side of the window and select "New" from the menu, then click "Activity" from the list of options. Android Studio will then list a list of templates for developers, including blank activity, fullscreen activity, and tabbed activity.

You can also select "Image Asset" from the menu, and the next wizard will guide us through the process of creating a step-by-step procedure. Let's take a look at how to create a new set of activity based on the login activity template. First select the Login activity option in the Acivity Template list to start the Create wizard.

As you can see in the above, I have named the newly created activity loginactivity--the layout name--for activity login and added a title named sign in to the activity. By default, the include Google + sign in item in the dialog box is checked. Since we are not going to use the Google + sign-in feature in today's example, uncheck the Tick option.

You can choose to set the hierarchical Parent (hierarchy) for this new activity. So when we click the Back button on the device, the app will navigate back to the previous interface. We leave this field blank. After clicking "Finish", Android Studio will create the necessary files and folders for us. If everything goes well, we will see new activity and layout in the project.

The next piece of work is to set up the new activity in the manifest file so that it can be used as the primary activity when the application starts. Please take a look at the following manifest file content, where the Loginactivity class has its own active node.

<application         Android:allowbackup="True" Android:icon="@drawable/ic_launcher" Android:label="@string/app_name" Android:theme="@style/apptheme" > <activity Android:name="Com.tuts.HelloWorld.MainActivity" Android:label="@string/app_name" > <intent-filter> <action Android:name="Android.intent.action.MAIN" /> <category Android:name= "Android.intent.category.LAUNCHER"  / > </intent-filter> </ Activity> <activity android:name< Span class= "pun" >= "com.tuts.HelloWorld.LoginActivity"  = "@string/title_activity_login"  android:windowsoftinputmode= "adjustresize|statevisible" Span class= "PLN" > > </activity> span class= "tag" ></APPLICATION>            

In order to launch the loginactivity we just created in the application, we first need to remove the active node from the original Loginactivity class and then use the Com.tuts.HelloWorld.LoginActivity replaces the previous com.tuts.HelloWorld.MainActivity. In this way, the application will now use the Loginactivity class as its main activity.

<application         Android:allowbackup="True" Android:icon="@drawable/ic_launcher" Android:label="@string/app_name" Android:theme="@style/apptheme" > <activity Android:name="Za.co.helloworld.LoginActivity" android:label= "@string/app_name"  > <intent-filter> span class= "tag" ><action android:name=  "Android.intent.action.MAIN"  /> <category android:name= />  </intent-filter> </activity></APPLICATION>             

When we create and run our own applications in the simulator, we should first see the display as shown. This means that we have successfully replaced the original blank activity class with the Loginactivity class that we just created.

5.Lint Tools

Testing the code is one thing, but just as important, we also need to introduce a variety of best practices while writing code. This not only improves performance significantly, but also increases the overall stability of the application. In addition, projects that have been properly restructured are easier to maintain.

Android Lint, available in Android Studio, is a static analysis tool that analyzes project source code. It detects potential vulnerabilities in the application and other code issues that may be overlooked by the compiler.

As an example of this, you can see that the linearlayout in this layout is not actually being used. The advantage of Android lint is that it helps us to focus on the causes of warnings or error messages, making it easier to fix or resolve them.

Make a habit of reusing the Android Studio Lint tool, which helps us to accurately detect potential problems in the project. The lint tool can even tell us if there are duplicate images or compiled content in the application.

To run the lint tool, you first need to select "Inspect Code ..." in the "Analyze" menu in Android Studio. When Android studio finishes detecting a project, it displays the results of the analysis at the bottom of the window. Please note that in addition to Android Lint, Android Studio offers a range of other check functions. Simply double-click on an already discovered problem and the system will help you navigate to the location of the problem in the corresponding file.

6. Rich Layout Editor

Android Studio offers a rich layout editor where you can easily drag and drop various user interface components. You can also see how multiple layouts are displayed in a multi-screen configuration, as we mentioned earlier in this article.

This rich layout editor is intuitive and straightforward to use. We first need a set of layout scenarios to work with. Browse to the Layout folder under the Res folder in your project, right-click the Layout folder and select New>layout resource file from the popup menu.

Next, set a name and root for the new layout and click "OK". Android Studio will automatically open the layout in the editor on the right side of the window.

At the bottom of the editor, you will see two tabs, respectively, design and text. When you click the Text tab, the editor is activated so that we can make changes to the currently selected layout scheme.

Clicking on the Design tab activates another set of editor content, which shows the layout's preview effect. To add other functional components to the layout, we simply drag them out from the list of components on the left side of the layout and put them inside the layout. Yes, it's so simple.

Summarize

In today's tutorial, we have a brief look at the core features of Android Studio. It is very similar to IntelliJ idea, but contains a number of important improvements that greatly accelerate the development of Android applications and make the process easier and more enjoyable.

The most comprehensive use of Android studio tutorials

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.