The activity is the user interface of the Android application, and the interface we see is the visual display of the activity. An activity is a container for a control, a Button,textview label, a drop-down list, and other controls that can be placed in an activity. Android interacts with the user through activity. This is similar to the C # form application design, where activity is a window in which various controls can be added.
There can be multiple activity in a program that requires registering information in the Androidmanifest.xml file, including the name of the activity, the label, and so on. And you need to specify in the Androidmanifest.xml file which activity to run first when the application starts, and this activity is the first interface we see. When we create a project, we automatically create a class that inherits from the activity class. We need to rewrite the OnCreate () method in the class, where each activity executes first with the OnCreate () method.
01.package org.leo.android;
03.import android.app.Activity;
04.import Android.graphics.Color;
05.import Android.os.Bundle;
06.import Android.widget.Button;
07.import Android.widget.TextView; 09.public class Helloandroid extends activity {10. /** called the activity is a. * * 11. @Override 12. public void OnCreate (Bundle savedinstancestate) {13.
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.main);
TextView textview= (TextView) Findviewbyid (R.id.textview);
Button button= (button) Findviewbyid (R.id.button);
Textview.settext ("Preliminary activity, TextView Text control");
Button.settext ("button buttons"); {}.}
Next look at the layout of an activity, what controls are in the activity, and the size, location, color, and so on of the control are determined by the layout XML file in the Res/layout folder. There can be more than one layout file in the Layout folder, and the Setcontentview () method is called in the OnCreate () method to select which layout file to use for an activity, and the parameter is "r.layout. layout file name". The Setcontentview () parameter can also be a control. A layout file Main.xml is automatically generated in the project. Multiple activity can use the same layout file. The root tag in a layout file is a layout control, such as a linear layout control linearlayout, and other controls are nested within a layout control, and we can add text controls, button controls, and so on.
Main.xml:
01.<?xml version= "1.0" encoding= "Utf-8"?> 02.<linearlayout xmlns:android=
"http://schemas.android.com" /apk/res/android "
. android:orientation= "Vertical"
. Android:layout_width= "Fill_parent"
. android:layout_height= "Fill_parent"
. >
modified. <!--distributes--> from top to bottom in linear layout controls
. <!--width fills the parent container-->
. <!--highly filled with the parent container -->
10.<textview
. Android:id= "@+id/textview"
. Android:layout_width= "Fill_parent"
. android:layout_height= "Wrap_content"
. />
. <!--register the TextView ID in the R.java file to reference--> through R.java files in other files
. <!--width fills the parent container, which is the LinearLayout control-->
. <!--height is compatible with content -->
18.<button
. Android:id= "@+id/button"
. Android:layout_width= "Match_parent"
. android:layout_height= "Wrap_content"
. />
. <!--Register the button's ID in the R.java file to refer to--> in other files through the R.java file
. <!--the same as Fill_parent effect -->
25.</linearlayout>