Android-TextView of common controls, android-textview

Source: Internet
Author: User

Android-TextView of common controls, android-textview

TextView is an Android text control used to display text.

Let's take a look at the structure of TextView (developer.Android. Com)

From this we can know that TextView is a subclass of View, which has direct subclasses such as Button and EditText.

 

Next, let's take a look at the xml attributes of TextView.

 

Android: EMS

Set TextView width to N characters

Android: maxems

Set the TextView width to a maximum of N characters. Overwrite the EMS option when used with EMS

Android: maxLength

Limit the number of input characters

Android: lines

Set the number of lines of text

Android: maxLines

Sets the maximum number of lines displayed for the text. If the number of lines exceeds the limit, the text will not be displayed.

Android: lineSpacingExtra

Set row spacing

Android: lineSpacingMultiplier

Set the line spacing multiple

Android: password

Display text in password format

Android: numeric

If this parameter is set, a digital input method (Edittext attribute) is displayed)

Android: phoneNumber

Set as the telephone number Input Method

Android: singleLine

Set single row display

Android: textAppearance

Set the text appearance.

Android: textColor

Set text color

Android: textColorHighlight

Background Color of the selected text

Android: textColorHint

Set the color of the prompt text. The default value is gray. Used with hint

Android: textColorLink

Text Link color

Android: textScaleX

Set text Interval

Android: textSize

Set the text size, recommended measurement unit "sp"

Android: textStyle

Set the font

Android: typeface

Set text font

Android: drawableTop

Set the image above the text

Android: drawablePadding

Set text and image spacing

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

How to use attributes? The properties of the control are used in the xml file. Next we open the activity_main.xml file in layout.

Switching to the code mode does not require dragging controls for real android development !!!

The root node is a viewgroup control. viewgroup indicates that this control can contain many controls, such as our layout control. The layout control can contain many controls.

1 <LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android" 2 xmlns: tools = "http://schemas.android.com/tools" 3 android: layout_width = "match_parent" 4 android: layout_height = "match_parent"> 5 <! -- Enter TextView in the middle area --> 6 7 </LinearLayout>

Input in the intermediate area

<TextView android:layout_width="match_parent"    android:layout_height="wrap_content"    android:text="@string/app_name"    android:textColor="#8A2BE2"    android:textSize="30sp"    />

Note: In the layout file, the android: layout_width and android: layout_height attributes must be added to all controls! It indicates the width and height of the control on the screen. Generally, there are three values.

1. match_parent: The component is displayed as big as its parent component.

2. wrap_content: the size of the component content,

3. fill_parent: It means match_parent. match_parent will be used later than 2.2.

After this TextView is written, it displays purple text and the font size is 30sp. The other attributes of TextView will be handed over to you for trial.

 


How does the android TextView control display array content?

Textview is used to display a text. You can convert the array into a string, and then settext will work... Pai_^

Textview control in Android

Like fill_parent match_parent, fill_parent is earlier than 2.1. Officially changed to match_parent after 2.2, and we recommend that you use this name. Because it is more in line with his intention. That is, it is determined by the parent container. For example, if a horizontal linear layout has a width of 200 and two buttons with a width of 50 and match_parent, the layout (parent container) sets the width of the second one to 150.

Wrap_content contains its own content and determines its size based on the display size of its content.

This is the intention. It would be a little more complicated to control with weights.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.