This example summarizes the TextView control usage of Android development. Share to everyone for your reference, specific as follows:
The TextView control can present text information to the user, and we can set whether the text information can be edited
1, TextView Basic use
To create a TextView object in a program
Layout in an XML file using the
2, New Android project->
Project Name:textview
Build Target:android 2.2
Application Name:textviewdemo
Package name:com.b510.textview.activity
Create activity:mainactivity
Min SDK Version:8
Finish
So our project is built up.
3, add the TextView control in the Mainactivity.java file
public class Mainactivity extends activity{public
void OnCreate (Bundle savedinstancestate) {
super ( Savedinstancestate);
Setcontentview (r.layout.main);
TextView tv=new TextView (this);
Tv.settext ("Hello");
Setcontentview (TV);
}
}
This program is relatively simple, only one control, if there are many brother control, then we need to write a lot of code to carry out the layout of the control, so that for our future maintenance will bring great difficulties. So, in Android development, it's recommended to use an XML file for control layout
4. Add controls to the Main.xml file
<textview
android:id= "@+id/mytextview"
android:layout_width= "fill_parent"
android:layout_height = "Wrap_content"
android:text= "Hello"
/>
Run the program again, "Hello" will be on the emulator output
Our programs need to be used by a lot of people, look sure to do beautiful, put in the XML file, we can easily modify his appearance, at the same time, the artist to design the XML file, the programmer is responsible for coding, the artist does not care about how the code is designed, and web development is very similar, Art staff focus on the page, do the backstage to focus on the design of the background code, they do not interfere.
5, TextView Property
To set the font size recommend using an SP as a unit
Use DP (DIP) as a unit when setting properties such as width or height
6. Set the Super chain
Android:autolink the text is displayed as a clickable link when the/email/phone number/map is linked to a text URL
android:autolink= "Phone"
7, set the font color
Android:textcolor= "#00FF00"
8, the effect of the happy lantern
Android:ellipsize How does the control display when the text is too long?
start-ellipses appear at the beginning
End-ellipses appear at the end
middle-ellipses appear in the middle
Marquee-in the way of a racing lamp
<!--countless times of running-->
android:marqueerepeatlimit= "Marquee_forever"
< get focus when!--touch-->
Android:focuseabletouchmode= "true"
<!--single-line display-->
Android:singleline= "true"
For more information on Android-related content readers can view the site topics: "Android Development Introduction and Advanced Course", "Android Multimedia operating skills Summary (audio, video, recording, etc.)", "Android Basic Components Usage Summary", " Android View tips Summary, Android layout layout tips and a summary of Android controls usage
I hope this article will help you with the Android program.