Okay. Let's get started with my first Android app!
Open eclipse, choose File> New> other, and select Android Application project and next. The following dialog box is displayed.
The Application name, project name, and package name (written by Java package name) must be filled in sequence. Others are configured by default.
The next page is still the default one. Next.
On the next page, it is time to select the icon. The system will automatically generate four kinds of icons for the application.
Next, select to create a blank activity. Default name.
Then, a super simple application was born.
The system automatically generates the following file tree for me.
Next I will briefly introduce the important file functions.
Hello project name
|-Res stores all resources used by Android apps, including images, strings, colors, sizes, etc.
|-Values
|-Strings. xml stores string Resources
|-Layout: stores interface layout files
|-Activity_main.xml
|-Drawable-ldpi, drawable-mdpi, drawable-hdpi, drawable-xhdpi
|-Src
|-Com. xujin. Hello
|-Mainactivity. Java
|-Gen
|-The files automatically generated by R. Java cannot be modified.
|-Androidmanifest. xml
The system list file of the android project controls the overall attributes such as the name, icon, and access permission of the android application.
The following is a list of my first applications:
Layout file activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:text="@string/hello_world" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:text="@string/hello" /></RelativeLayout>
This is a correlation layout relativelayout, where there are two texts, textview represents a text box.
The mainactivity. Java file is as follows,
package com.xujin.hello;import android.os.Bundle;import android.app.Activity;import android.view.Menu;public class MainActivity extends Activity {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);}@Overridepublic boolean onCreateOptionsMenu(Menu menu) {// Inflate the menu; this adds items to the action bar if it is present.getMenuInflater().inflate(R.menu.activity_main, menu);return true;}}
The purpose of this file is,
1) set setcontentview (R. layout. activity_main) when applying oncreat; Use activity_main.xml as the layout File
2) setting is the setting button displayed after pressing menu on the mobile phone.
The following is my final result: