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