Intellij idea development of the first Android app

Source: Internet
Author: User

1. Create a project

File-->new Project --... -- >finish

2. Create a module

3, Myactivity.java

Package Com.example.myapp;

Import android.app.Activity;

Import Android.app.AlertDialog;

Import Android.os.Bundle;

Import Android.view.View;

Import Android.widget.Toast;

public class MyActivity extends Activity {

/**

* Called when the activity is first created.

*/

@Override

public void OnCreate (Bundle savedinstancestate) {

Super.oncreate (savedinstancestate);

Setcontentview (R.layout.main);

}

public void Onmybuttonclick (view view) {

Toast.maketext (This, " Hello! ", Toast.length_short). Show ();

}

public void Onmybutton2click (view view) {

Alertdialog.builder Builder = new Alertdialog.builder (myactivity.this);

Builder.settitle (" title ");

Builder.setpositivebutton (" OK ", null);

Builder.seticon (Android. R.drawable.ic_dialog_info);

Builder.setmessage (" Simple message box ");

Builder.show ();

}

}

4,layout-->main.xml (layout file)

<?xml version= "1.0" encoding= "Utf-8"?>
<linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"
android:orientation= "Vertical"
Android:layout_width= "Fill_parent"
android:layout_height= "Fill_parent"
>
<textview
Android:layout_width= "Fill_parent"
android:layout_height= "Wrap_content"
android:text= "Hello world,my name is Liurui."
/>
<button
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
Android:text= "Button1 "
android:onclick= "Onmybuttonclick"
Android:id= "@+id/button" android:layout_gravity= "Center_horizontal"/>
<button
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
Android:text= "Button2 "
android:onclick= "Onmybutton2click"
Android:id= "@+id/button2" android:layout_gravity= "Center_horizontal"/>
</LinearLayout>

5. Values-->strings.xml

<?xml version= "1.0" encoding= "Utf-8"?>

<resources>

<string name= "App_name" >myapp</string>

<string name= "Hello" >hello world! My name is liurui.</string>

</resources>

6, Gen-->r.java

/*___generated_by_idea___*/

Package Com.example.myapp;

/* This stub was only used by the IDE. It's not the R-class actually packed into the APK * *

Public final class R {

public static final class Attr {

}

public static final class Drawable {

public static final int icon=0x7f020000;

}

public static final class layout {

public static final int main=0x7f030000;

}

}

7. Operation

Run-->run'myapp'

Intellij idea development of the first Android app

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.