In this chapter, we will talk about the use of common controls.
The same applies to most chapters in the future. We will discuss the usage of some controls in detail. As long as these controls are combined, they are an application.
Let's take a look at how to use this control.
As you may find, the content of this control is defined in strings. xml in the values folder.
Then we only need to add a piece of code to it:
[Java]
<String name = "test"> Welcome to Joven \'s blog </string>
<String name = "test"> Welcome to Joven \'s blog </string>
Then bind to the control
[Java]
<TextView
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: text = "@ string/test"/>
<TextView
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: text = "@ string/test"/>
You can. Let's take a look at the effect.
In fact, there is another second method, which is also the most commonly used method and is obtained dynamically.
We add an ID to TextView and write it in main. xml as follows:
[Java]
<TextView
Android: id = "@ + id/tv1"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: text = "@ string/test"/>
<TextView
Android: id = "@ + id/tv1"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: text = "@ string/test"/>
Then dynamically bind it to the activity and write it in TestDemo. java as follows:
[Java]
Package com. example. testdemo;
Import android. OS. Bundle;
Import android. app. Activity;
Import android. view. Menu;
Import android. widget. TextView;
Public class TestDemo extends Activity {
Private TextView TV;
@ Override
Protected void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
SetContentView (R. layout. main );
// Bind the textview control with the id of tv1 to the view.
TV = (TextView) findViewById (R. id. tv1 );
// Dynamically set the control content.
TV. setText ("Welcome! ");
}
}
Package com. example. testdemo;
Import android. OS. Bundle;
Import android. app. Activity;
Import android. view. Menu;
Import android. widget. TextView;
Public class TestDemo extends Activity {
Private TextView TV;
@ Override
Protected void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
SetContentView (R. layout. main );
// Bind the textview control with the id of tv1 to the view.
TV = (TextView) findViewById (R. id. tv1 );
// Dynamically set the control content.
TV. setText ("Welcome! ");
}
}
Now let's look at the effect:
In terms of priority, the program loads the resource file and then the activity. Therefore, the latter's settings will overwrite the former.