Android development on IDEA

Source: Internet
Author: User
Introduction:

IntelliJ IDEA supports the development of applications running on mobile phones, so it can also run in the Android operating system. In addition to the common code prompting assistant function, this IDE allows you to test the Android program by configuring the simulator device.

IntelliJ IDEA help prompt:

· Create an Android program using the New Project Wizard

· View the Android program in the tree-view of files and folders

· Create elements of the Android program and manage file resources, such as strings and colors. You can view closely related resources through R. java.

· Run the program (txlong_onz)

· Configure the simulator and run the program on the simulator

 

Next we will teach you how to develop and run a simple Android Application through IntelliJ IDEA step by step.

Prerequisites:

· You must go to IntelliJ IDEA Ultimate 9 or later

· Install JDK.

· Then we need to have the Android SDK. This is nonsense. I will use SDK2.2 FroYo.

Create a Project

Let's start the program. First, create the project

Select File> New Project, or click Create a New Project on the welcome page.

On the homepage of the New Project, you must first confirm that the Create project from scratch option is selected.

Specify the Project name on the following page, Create module, select Android Module as the Project type in the selection box, and name the Project android_hello_world.

Select the Create source directory option on the third page, and then we generally accept the default src name.

When you create a Project for your IDE for the first time, you have not configured JDKs (Java SDKs) for the IDE. This means that the IDE does not know where the local JDK directory is located, let alone install several JDK versions on your computer. In this case, IntelliJ IDEA allows you to create a JDK to your project, click the Configure button, and specify your own JSDK through the file list, if you find the local JDK, you can click OK to add a JDK path to our project. In the future, this path will become the default JDK path of IDE, all programs can be used.
Finally, we need to specify the Android SDK and our IDE. Click New to SDK properties and select the Android platform to be used by an application.


Go to the select path dialog box and specify the path to the directory of our Android SDK.

Click OK to go to the Select Android Build Target dialog box. In this dialog box, we can specify the version of Android platform that our project will use.

After you select OK, the next step is to select Android Platform, (1) is to select the list, if a simple application is selected (2) Create "Hello, World! "Project Selection box, which accepts the default activity as MyActivity (3)

When you click Finish, IDEA automatically generates the directory structure of the application. Let's take a look at its structure.

Browse an Android Application

To browse our programs, we need to use the Project View tool to view files and folders, as shown in

| --. Idea (1) this folder contains a series of subfolders, mainly including information inside IntelliJ IDEA.
| -- Src (2) this folder contains the source files used by applications such as MyActivity. java (3). These file terms are the com. example package.
| -- Res (4) the folder contains the resources used.
| -- Layout/main. xml (5) the folder contains the appearance of the pages used by each page.
| -- The values (6) folder contains the String. xml file, which is mainly used for the definition of the String used by the project. You can also add the color. xml file to add the color used by our application.
| -- Drawable (7) contains the project's image resources
| -- Gen (8) This folder is used to package the R. java file to link the resource files used by the entire project. IntelliJ IDEA will help us automatically generate R. java to closely associate it with our resource files. The R. java file is automatically regenerated as long as you add or delete Resources in the project. R. java also belongs to the com. example package

Add features to your application:

The following describes a program writing process. First, open our HelloWorld application and expand all the directory structures to open our MyActivity. java (1). Here we can see the layout/main associated with this Activity. the xml file defines the appearance of its Activity.

Now, let's open the main. xml (3) file. Here IntelliJ has helped us list the Mappings of hello in the res/values/strings. xml file.

We need to add three things for our application, one layout, one string, and one color for display.

Add String

Add the last tag in the main. xml file <LinerLayout/>

Xml Code
  1. <TextView android: layout_width = "fill_parent"
  2. Android: layout_height = "wrap_content"
  3. Android: text = "@ string/explanation"
  4. />
<TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/explanation"/>

Then you will see IntelliJ idea highlighted in red to show Code that cannot be parsed.

We are glad that you can use Alt + Enter to automatically fix the error (1), which will help you add your missing string configuration in strings. xml.

IntelliJ helps us add strings that we have not added.

The application description is included in the string tag (<string/>) for example:

This simple Android program describes the application of IntelliJ IDEA file stream in the Android development environment.

If you open the R. java file, you will find that IntelliJ IDEA has added the new string to the string resource.

Now let's add the color string string_color resource definition.

Double-click a color. xml file in the Project window and open the color. xml file in the compilation window. Add the hexadecimal identifier starting with "#" (1) to define the color resource within the resources tag. For example, # ff00ff77

IntelliJ IDEA helps us to add colors by preprocessing (2)

Add color Resource

Now let's start to define the color display string. Before doing this, let's create a color resource file to define string_color.

In the tree column of the Project window, you can clickValuesFolder (1) SelectNew-> Values resource file(2 ). InNew values resource fileIn the dialog, specify the color and create a new file (3 ).

Click OK. IntelliJ IDEA will help us create a new file:

 

Now, let's addString_color resource definition. Double-click to open the Project viewColor. xml file.. Add<Resources/> label, and then define the color.

Xml Code
  1. <Color name = "string_color"> hexadecimal format starting with # </color>
<Color name = "string_color"> hexadecimal format starting with # </color>

In my example, the color is #Ff00ff77, as you see (1 ),IntelliJ IDEA shows us your defined color in the left area (2 ):

 
Just as you guessed, all these configurations are mappedR.java:

Now, let's apply the string we just defined. InMain. xml file, search<TextView/> label and add the property text:

Html code
  1. <TextView android: layout_width = "fill_parent"
  2. Android: layout_height = "wrap_content"
  3. Android: text = "@ string/explanation"
  4. />
<TextView android:layout_width="fill_parent"                android:layout_height="wrap_content"                android:text="@string/explanation"            />

Use the configured string: android: text = "@ string/explanation" through the application in the preceding section"

Xml Code
  1. Android: textColor = "@ color/string_color"
android:textColor="@color/string_color"

How to use a color string

Run your application

During project creation, IntelliJ IDEA automatically generates the running configurationAndroid_hello_world.To run the program immediately, we only need to configure the virtual device or directly use the mobile phone to run the program.

Configure a virtual Android device

SlaveRun/Debug Configuration(1) select from the listEdit Configurations.

Open IntelliJ IDEARun/Debug deploymentsDialog Box display default runAndroid_hello_worldDetailed device information configuration (1 ).

ClickBrowseClick Next to enterPrefer Android Virtual Device for DeploymentDrop-down list (2). HereSelect Android Virtual DeviceDialog box, clickCreate:

HereCreate Android Virtual DeviceThe dialog box opens to accept the default device named MyAvd0 (1 ):

When you clickOKThen, IntelliJ IDEA will let youSelect Android Virtual DeviceIn the dialog box, you can see the list of devices you have defined.

ClickOKSave the configuration and returnRun/Debug deploymentsDialog Box to enterPrefer Android Virtual Device for DeploymentThe following emulator is displayed in the drop-down list:

ClickOK.

Fortunately, you only need to configure this once, and IDE will help you remember this.

Run the program

Now that you have finished all the work, let's launch our application.

Click (2) in the toolbar and thenRun/Debug Configuration(1) select from the drop-down listAndroid_hello_worldSelected by default.


 

IntelliJ IDEA launches the emulator we configured:
 

Next, the IDE will showHello worldThe application is then displayed on the screen:

Congratulations! You can create a simple Android Application. (* ^__ ^ *) Xi ...... My translation work has been completed, class, I don't know whether it is useful or not. It seems that IntelliJ is rarely used now. However, to compare IDE, I still have nothing to eat, I really hope someone else can be of some use. Well, it is estimated that we will not stay up late to translate this. O (∩) O Haha ~

  • Size: 9 KB
  • The size is 6.8 KB.
  • The size is 2.7 KB.
  • The size is 12.9 KB.
  • Size: 7 KB
  • The size is 36.2 KB.
  • The size is 13.6 KB.
  • The size is 10.9 KB.
  • The size is 5.6 KB.
  • The size is 7.1 KB.
  • The size is 43.2 KB.
  • The size is 38.1 KB.
  • Size: 25 KB
  • The size is 8.8 KB.
  • The size is 55.7 KB.
  • The size is 8.6 KB.
  • Size: 20 KB
  • The size is 23.5 KB.
  • The size is 15.4 KB.
  • The size is 14.8 KB.
  • The size is 2.8 KB.
  • The size is 13.9 KB.
  • The size is 10.8 KB.
  • The size is 8.3 KB.
  • The size is 13.1 KB.
  • The size is 30.9 KB.
  • The size is 89.5 KB.
  • Size: 6 KB
  • The size is 1.2 KB.
  • The size is 2.8 KB.
Related Article

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.