This example describes the TextView control usage of Android programming. Share to everyone for your reference, specific as follows:
Here we will talk about the use of commonly used controls.
The same is true in most of the future chapters, and we will talk specifically about the use of certain controls. Because as long as these controls are grouped together, they are an application.
Okay, let's just see how this control is used.
Careful students will find, in fact, the content of this control is defined in the values folder inside the Strings.xml.
So we just need to add a code to it:
Copy Code code as follows:
<string name= "Test" >welcome to joven\ ' s blog</string>
Then bind to the control
<textview
android:layout_width= "wrap_content"
android:layout_height= "wrap_content"
android:text = "@string/test"/>
It's OK. Let's look at the effect.
In fact, there is a second method, but also the most commonly used method, is dynamically acquired.
Let's add an ID to TextView and write it in Main.xml:
<textview
android:id= "@+id/tv1"
android:layout_width= wrap_content "android:layout_height=" Wrap
_content "
android:text=" @string/test "/>
And then dynamically bind in the activity, which is written in the Testdemo.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);
A control TextView with ID TV1 in the bound view.
tv= (TextView) Findviewbyid (R.ID.TV1);
Dynamically set the content of the control.
tv.settext ("welcome!");
}
All right, let's see the effect:
Above the priority level, the program loads the resource file before loading the activity. So the latter's settings will overwrite the former.
I hope this article will help you with the Android program.