Now let's write the first android program and see what it brings to us. I will not talk about the use of sdks and the creation of virtual machines. It is not important to skip the project creation process.
What can we learn about the first program? Let's take a look. ^-^
Create an android project in IDE:
This is the next step.
After creating a project, Let's first look at the project structure:
Let's take a look at the effect (so far, the effect is very simple and there is nothing exciting)
What are in the program:
Program name: HelloWorld
Content: hello world!
Where are they defined? I only define the project name?
Before proceeding, let's talk about the preparations.
Activity (what is Activity)
Now let's take a look at what is in the layout directory.
By the way, it is an activity_main.xml file. What is its use? Anyone with web development experience knows index.html. By the way, it is the homepage. For now, let's call it an entry file.
So what is in it?
Let's see what they are.
RelativeLayout:Relative Layout. Anyone with Web development experience knows. They are indeed a bit like. (There are other la S)
TextView: Text View. Its only function is to store strings. So what is it like in html? By the way, it is the h tag, from h1 to h (n ). In addition to TextView, TextView does not have the automatic bold feature.
We seem to have seen a hello_world, but it is not like what we have seen above...
Okay, let's sayAndroid: textRole:
It is used to set the display text of TextView, which is the string displayed in the blank area above.Hello world
@ String/hello_world indicatesStrings. xmlFileValue in a string named hello_worldDisplay to TextView
As we have said before, string values can be placed in files under the values directory, so the strings. xml file is under this directory.
Strings. xml file structure:
HelloWorld Settings Hello world!
Have you seen it? Our long-awaited Hello world! It finally appears.
Resources labels indicate that these are all resource files.
At this point, the AndroidManifes. xm file is left blank.
First look at the Code:
Android: label displays the program name by referencing app_name In the strings. xml file.
@ String: references the strings. xml file.
@ Dimen: References The dimens. xml file.
Finally, the program presents this entry file to everyone through the MainActivity class under the src directory.
This is mainly done by the setContentView (R. layout. activity_main) method of the Activity class.
MainActivity }
Now, I will learn it here today and take notes here.