Follow me to learn the TextView of android-common controls

Source: Internet
Author: User

TextView is an Android text control that is used to display text.

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

From here we can know that TextView is the sub-class of view, he has direct sub-class Button,edittext, etc.

Next we understand the XML properties of the TextView

Android:ems

Sets the width of a textview to n characters

Android:maxems

Sets the width of the textview to a maximum of n characters. Overwrite EMS option when used in conjunction 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 of text to display, beyond the number of lines

Android:linespacingextra

Set line spacing

Android:linespacingmultiplier

Set a multiple of line spacing

Android:password

Display text as a password

Android:numeric

If set, it pops up with a numeric input method (EditText's properties)

Android:phonenumber

How to enter a phone number

Android:singleline

Set up single-line display

Android:textappearance

Sets the appearance of text.

Android:textcolor

Set Text color

Android:textcolorhighlight

The background of the selected text

Android:textcolorhint

Sets the color of the message text, which is grayed out by default. Use with hint

Android:textcolorlink

Color of text links

Android:textscalex

Set spacing between text

Android:textsize

Set text size, recommended unit of measure "SP"

Android:textstyle

Set font style

Android:typeface

Set Text font

Android:drawabletop

Set the picture above the text

Android:drawablepadding

Set the spacing between text and pictures

property to introduce you, how to use the property? The properties of the control are used in the XML file, and then we open the Activity_main.xml file in the layout.

Switch to code mode, real Android development is no need to drag and drop Controls!!!

The root node is a ViewGroup control, and since ViewGroup means that the control can contain a lot of controls, such as our layout control, the layout control can contain a lot of controls

1 <LinearLayoutxmlns: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 this middle area -6 7 </LinearLayout>

Everyone in the middle area input

<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, all controls must be prefixed with Android:layout_width and Android:layout_height 2 properties! He represents the width and height of the control on the screen and generally has a value of 3

1.match_parent: The component will appear as large as its parent component

2.wrap_content: How big the component content is, how big it is,

3.fill_parent: And match_parent a meaning, after 2.2 use match_parent

When this textview is written, the effect is to display the purple text, and the font size is 30sp. The other attributes of TextView are given to everyone to try.

Follow me to learn the TextView of android-common controls

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.