A simple Android Small instance

Source: Internet
Author: User

First, configure the environment1. Download IntelliJ idea152. Install the Android SDK and install or uninstall the Android platform via the Android SDK manager 3. Installing the JDK second, IntelliJ idea new Android Project1.file->new-project ... 2. Select Android->application Module, NextNote: It is recommended to select this item, which is a nearly empty project that can be run and a directory structure constructed with ant;gradle:android module, built by Gradle, differs from application module's ant buildEmpty Moudle is a blank project;The library module is used to build a shared code base.  3. Set project Propertiescontains the app name and package name, and whether to create an activity (and the name of the activity), click NextDescription: Creating an activity creates a class file with the same name, for example, Myactivity.class 4. Set the target deviceincluding project name, project location, SDK version and target device, click Finish, Project creation successNote: It is best to install the SDK in advance, or you can select the installation directory of the SDK from the right side, and then automatically detect the following Android platform;Target Device can choose a real USB device or a simulator emulator (I use a simulator here)  third, the structure of Android engineering program(see the catalogue of the projects that created the results can be referenced in this blog http://www.360doc.com/content/14/0425/16/9200790_372140391.shtml)an app can correspond to multiple activity. Each activity in the OnCreate state corresponds to an XML layout filePublic class MyActivity extends Activity {    /**
* Called when the activity is first created.
     */
@Override
Public void OnCreate (Bundle savedinstancestate) {
super.oncreate (savedinstancestate);
Setcontentview (r.layout.main);
InitializeApp ();
    }} Setcontentview (R.layout.main) is only a UI layout that uses Main.xml files under Res/layout Note: Before writing, it is recommended to understand the activity life cycle (I only write the status of OnCreate), refer to this blog http://kb.cnblogs.com/page/70125/  Iv. The Android UI layoutthe UI layout is defined by the file Res/layout/main.xml file.Open Main.xml can be seen in two modes, design and text. You can either drag the control design directly or tap the Code Editor (I feel a bit like Dreamweaver to design the page)Note: The layout file Main.xml file can be called Res/values under Strings.xml or color.xml valuesandroid:text= "@string/explanation"
android:textcolor= "@color/string_color" the contents of the Stirngs.xml file are as follows:<?xml version= "1.0" encoding= "Utf-8"?>
<resources>
<string name= "App_name" >android_hello_world</string>
<string name= "explanation" >hello~Android</string>
</resources> the contents of the Color.xml file are as follows:<?xml version= "1.0" encoding= "Utf-8"?>
<resources>
<color name= "String_color" > #ff00ff77 </color>
</resources> simple layout Get started suggest a look at this blog https://liuzhichao.com/p/337.html  v. The interactive nature of the procedure1. Get to the element firstFor example, get a button with ID button14, assign a value to the result variableresult = (Button) Findviewbyid (r.id.button14)2. Monitor the click Operation and respond accordinglyResult.setonclicklistener (New View.onclicklistener () {@OverridePublic void OnClick (View v) {#点击时的对应各种操作           }     });examples are as follows:import Android.widget.Toast;

Public class MyActivity extends Activity {
private TextView title;
private Button result;
private Button test;
private View.onclicklistener Droidtaplistener;
    /**
* Called when the activity is first created.
     */
@Override
Public void OnCreate (Bundle savedinstancestate) {
super.oncreate (savedinstancestate);
Setcontentview (r.layout.main);
InitializeApp ();
    }
private void InitializeApp () {
title = (TextView) Findviewbyid (r.id.text);
result = (Button) Findviewbyid (R.ID.BUTTON14);
test = (Button) Findviewbyid (R.id.button);
Result.setonclicklistener (New View.onclicklistener () {
@Override
Public void OnClick (View v) {
Toast TST = Toast.maketext (Myactivity.this, "111111111", toast.length_short);
tst.show ();
test.settext ("change!");
Title.settext ("was clicked, content changed = =");
            }
        });
    }}Description: Toast to create a toast promptSetText: The text of the corresponding element is re-assigned vi. configuration of Android program runningClick Edit Configurations in the top right corner ...To configure items such as target devices, the simulator emulator can drop down to select an existing emulator, or through the right ... To create a new simulatorafter saving, you can switch Android to your current project name and click the Execute button on the right to executeDescription: The process of execution includes compiling the build apk (under the name of the \out\production\ project in the created project catalog), installing the app on the configured emulator, and then seeing what you've designed.

A simple Android Small instance

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.