Some uses of activity
1. Open Android Studio,new a project
Start a application name:firstactivity (fully demonstrate our rookie quality first), click Next, select Phone and Tablet, the smallest SDK I choose 2.3.3,
Continue to click Next, would like to choose no activity, and later found a little trouble, so choose blank activity (rookie don't like too much trouble), to this, you have succeeded half (cheat you).
2, in order to let you fully understand an activity, first make a little damage (the following operation when the activity of the deletion and reconstruction process, well, I am really bored, not bored how do you understand the activity and which parts are related),
app/src/main/java/Package Name/mainactivity, select the right button to select Delete, in the popup dialog box, select
This will remove some of the corresponding file configurations. Same operation, remove Src/res/layout/layout_main.xml.
3, this step we will re-establish an activity. In the java/package name right, new a Java class (yes, you can new an activity, so we delete it makes no sense, we just want to build a little bit of activity)
The name is firstactivity, inheriting from activity, overriding the OnCreate () function.
4. Create a layout file. Res/layout Right-click New-xml-layout XML file
The name is First_layout,root Tag default LinearLayout (This is a way of layout, there are three other kinds, in here first don't say, rookie, know too much bad).
It has two switch cards, design and text below it, in design you can drag and drop the control, it will generate the corresponding text in the corresponding code, the other is also set (text in the handwriting code, also reflected in the design).
Then you can draw a gourd. To explain, orientation: "Vertical" represents the vertical arrangement of space to be added later. Here is the addition of a button. The first line refers to the width of the button, match_parent means
More than this his father, can be as wide as wide, here is as wide as the screen. The second sentence is the height, "wrap_content" means to determine the height according to the contents of the button above.
The third sentence is what is displayed on the button. The sentence is ID, this is important, we generally call through r.id.button_1. R is a file that automatically generates an ID for the control.
In fact, the ID of this sentence on the top, that is, the position of the first sentence, but the picture was cut off I found that you put this sentence in the first sentence of the position, do not be capricious.
5. Add this layout to the event. Add Setcontentview (r.layout.first_layout) to the OnCreate () function in firstactivity;(found, file invocation is usually done by R)
6, in Androidmanifest.xml to register the activity.
Name of the string in front of why there is a point, is not very awkward, in fact, he is in front of the name of the activity omitted your package name. Plus it's the same drip. The label is the title name of the activity and the name that is displayed after the application is installed.
The following two sentences, let firstactivity as our main activity of this program, that is, click the Desktop application icon when the first open is this activity (there is a lot of doubt, nothing to worry about, first so get, will slowly understand the pain of growing up).
Well, so far, our activities have been finished, you can run a try, in the run may encounter the simulator a variety of problems, don't worry, because you will get used to.
In the following, we'll cover the hidden title bar and use menu in the activity.
Hiding the title bar is simple, add a line of code in the OnCreate () function, requestwindowfeature (window.feature_no_title); This code must be executed before Setcontentview (), Otherwise it will be an error.
Android Studio Series 2 Some usage of activity