Android Development Study Notes (2) My first Android Application

Source: Internet
Author: User

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:

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.