reference from article: Http://www.runoob.com/w3cnote/android-tutorial-textview.html
1. The underlying attributes are detailed:
- ID: Set a component ID for TextView, depending on the ID, we can get to the object in Java code through the Findviewbyid () method, and then set the related properties, or when using Relativelayout, Reference components are also used for id!
- layout_width: The width of the component, generally write: **wrap_content** or **match_parent (fill_parent) * *, the former is how large the control is displayed, how large the control is, The latter fills the parent container where the control is located, and of course it can be set to a specific size, for example, I have set it to 200DP for the purpose of displaying the effect.
- layout_height: The width of the component, same as the contents.
- Gravity: Sets the alignment direction of content in the control, text in TextView, pictures in ImageView, and so on.
- Text : set the display of textual content, generally we are to write the string into the String.xml file, and then through the @string/xxx to obtain the corresponding string content, here in order to facilitate my writing directly to "", do not recommend this write!!!
- TextColor: Set the font color, as above, by Colors.xml resources to reference, do not write it directly!
- textStyle: set font style, three selectable values: **normal** (no effect), **bold** (bold), **italic** (italic)
- textSize: font size, unit is generally used sp!
- background: The background color of the control, which can be understood to fill the entire control's color, can be a picture Oh!
2. Actual development Example 2.1 shaded TextView
Several properties are involved:
- Android:shadowcolor: set shadow color, need to use with Shadowradius Oh!
- Android:shadowradius: Set the blur level of the shadow, set to 0.1 to become a font color, it is recommended to use 3.0
- ANDROID:SHADOWDX: Sets the offset of the shadow in the horizontal direction, which is the horizontal position where the shadow begins.
- Android:shadowdy: Sets the offset of the shadow in the vertical direction, which is the vertical position where the shadow begins.
<TextViewAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"android:layout_centerinparent= "true"Android:shadowcolor= "#F9F900"ANDROID:SHADOWDX= "10.0"Android:shadowdy= "10.0"Android:shadowradius= "3.0"Android:text= "TextView with Shadows"Android:textcolor= "#4A4AFF"android:textsize= "30SP" />
2.2 TextView with border:
If you want to set a border background for textview, normal rectangular border or rounded border! The following may help you! In addition, TextView is the parent of many other controls, such as button, and you can set such a border! The principle of implementation is very simple, write a shapedrawable resource file yourself! Then TextView set Blackgroung to this drawable resource!
Briefly say several nodes and attributes of the shapedrawable resource file:
- <solid android:color = "XXX" > This is the setting of the background color
- <stroke android:width = "XDP" android:color= "xxx" > This is the thickness of the set border, and the color of the border
- <padding androidlbottom = "XDP" ...> this is the setting of the margin
- <corners android:topleftradius= "10px" ...> this is the setting of rounded corners
- <gradient> This is to set the gradient, optional properties are: startcolor: Start color endcolor: End color centercolor: Middle color Angle: direction angle, equal to 0 o'clock, left to right, then counterclockwise, when angle = 90 degrees from bottom to top type: Set gradient types
<?XML version= "1.0" encoding= "Utf-8"?><Shapexmlns:android= "Http://schemas.android.com/apk/res/android" > <!--set a black border - <StrokeAndroid:width= "2px"Android:color= "#000000"/> <!--Gradient - <GradientAndroid:angle= "+"Android:endcolor= "#C0C0C0"Android:startcolor= "#FCD209" /> <!--set a bottom margin to make the space a little bigger - <paddingAndroid:left= "5DP"Android:top= "5DP"Android:right= "5DP"Android:bottom= "5DP"/></Shape>
2.3 TextView with Picture (DRAWABLEXXX):
Basic usage:
Set the core of the picture is actually:drawablexxx; You can set a picture in four directions:drawabletop(top),drawablebuttom(bottom), Drawableleft(left),drawableright(right) Alternatively, you can also use the drawablepadding to set the spacing between the picture and the text!
: (set a picture in four directions)
Implementation code:
<Relativelayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Xmlns:tools= "Http://schemas.android.com/tools"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"Tools:context= "Com.jay.example.test.MainActivity" > <TextViewAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"android:layout_centerinparent= "true"Android:drawabletop= "@drawable/show1"Android:drawableleft= "@drawable/show1"Android:drawableright= "@drawable/show1"Android:drawablebottom= "@drawable/show1"android:drawablepadding= "10DP"Android:text= "Zhangquan egg" /> </Relativelayout>
Some questions: You may find that the drawable we set up in this way cannot be set by itself and cannot be set directly in XML, so we need to make a change in Java code!
The sample code is as follows:
Packagecom.jay.example.test; Importandroid.app.Activity; Importandroid.graphics.drawable.Drawable; ImportAndroid.os.Bundle; ImportAndroid.widget.TextView; Public classMainactivityextendsActivity {PrivateTextView TXTZQD; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (R.layout.activity_main); TXTZQD=(TextView) Findviewbyid (R.ID.TXTZQD); Drawable[] drawable=Txtzqd.getcompounddrawables (); //The following table 0~3, followed by: top left and bottom rightDrawable[1].setbounds (100, 0, 200, 200); Txtzqd.setcompounddrawables (drawable[0], drawable[1], drawable[2], drawable[3]); } }
Run:
Android Learning note-textview (text box) (i)