Android --- details about TextView attributes

Source: Internet
Author: User

1. TextView control Overview

The TextView control can be used to display text information (including HTML text). You can manually set it to editable or uneditable. In main. xml, add the TextView configuration section to create, design basic attributes, width, height, color, font size, etc.

2. Common attributes of TextView controls

Android: autoLink: sets whether the text is displayed as a clickable link when the text is URL link, email, phone number, or map. Optional values (none/web/email/phone/map/all)
Android: autoText: If set, the spelling of the input value is automatically corrected. There is no effect here. It works when the input method is displayed and entered.
Android: bufferType: Specifies the text category obtained by getText. The editable option is similar to StringBuilder: appendable characters, that is, after getText, you can call the append method to set text content. Spannable: The style can be used in the given character area. For more information, see 1. 2.
Android: capitalize: Set uppercase letters. There is no effect here. The input method needs to be popped up to see it. For details, see EditView this attribute description.
Android: cursorVisible: Set the cursor to show/hide. The default value is displayed.
Android: digits: Specifies the characters that can be entered. For example, "1234567890. +-*/% ()"
Android: drawableBottom: outputs a drawable under text. If a color is specified, the background of the text is set to this color, and the latter is overwritten with the background.
Android: drawableLeft: outputs a drawable on the left of text.
Android: drawablePadding: sets the interval between text and drawable (image). It can be used with drawableLeft, drawableRight, drawableTop, and drawableBottom. It can be set to a negative number, but it has no effect.
Android: drawableRight: outputs a drawable on the Right of text.
Android: drawableTop: outputs a drawable on the top of the text.
Android: editable: sets whether to edit.
Android: editorExtras: set additional text input data.
Android: ellipsize: Set how to display the control when the text is too long. Set the following values: "start "-? The ellipsis is displayed at the beginning; "end" -- The ellipsis is displayed at the end; "middle" -- The ellipsis is displayed in the middle; "marquee" -- displayed in the form of a marquee (horizontal animation Movement)
Android: freezesText: Set the content of the saved text and the position of the cursor.
Android: gravity: sets the text position. For example, if it is set to "center", the text is displayed in the center.
Android: hintText: Text prompt information displayed when it is null. You can use textColorHint to set the color of the prompt information. This attribute is used in EditView, but it can also be used here.
Android: imeOptions: additional function. It sets the IME action and the action related to the edit box in the lower right corner. For example, a "finish" is displayed in the lower right corner of actionDone, without setting a carriage return symbol by default. This is described in detail in EditView, Which is useless here.
Android: imeActionId: sets the IME action ID.
Android: imeActionLabel: sets the IME action label.
Android: includeFontPadding: sets whether the text contains additional white space at the top and bottom. The default value is true.
Android: inputMethod: Specifies the Input Method for text. You must specify the full package name ). For example, com. google. android. inputmethod. pinyin, but the error cannot be found.
Android: inputType: Set the text type to help the input method display the appropriate keyboard type. Detailed description in EditView, no effect here.
Android: linksClickable: sets whether the link is connected even if autoLink is set.
Android: marqueeRepeatLimit: When marquee is specified in ellipsize, the number of repeated scrolling times is set. When marquee_forever is set, the number of times is unlimited.
Android: EMS: Set the TextView width to N characters. The test here is a Chinese character width.
Android: maxEms: Set the TextView width to a maximum of N characters. Overwrite the EMS option when used with EMS.
Android: minEms: Set the TextView width to the width of a minimum of N characters. Overwrite the EMS option when used with EMS.
Android: maxLength: restrict the length of the displayed text. The excess part is not displayed.
Android: lines: sets the number of lines in the text. If two lines are set, two lines are displayed, even if the second row has no data.
Android: maxLines: sets the maximum number of lines displayed in text. This parameter is used in combination with width or layout_width. If the line exceeded is automatically wrapped, the line exceeded is not displayed.
Android: minLines: sets the minimum number of lines of text, similar to lines.
Android: lineSpacingExtra: Set the line spacing.
Android: lineSpacingMultiplier: Set the line spacing multiple. For example, "1.2"
Android: numeric: If set, the TextView has a digital input method. This is useless. The only effect after setting is that TextView has a click effect. This attribute is described in detail in EdtiView.
Android: password: show text in a small dot "."
Android: phoneNumber: Enter the phone number.
Android: privateImeOptions: it is useless to set the input method options. It will be further discussed in EditText.
Android: scrollHorizontally: sets whether to display a horizontal bar when the text exceeds the TextView width.
Android: selectAllOnFocus: if the text is selectable, let him get the focus instead of moving the cursor to the start or end of the text. After being set in TextView, there is no effect.
Android: shadowColor: Specifies the color of text shadow, which must be used with shadowRadius.
Android: shadowDx: sets the start position of the Shadow horizontal coordinate.
Android: shadowDy: Set the start position of the Shadow vertical coordinate.
Android: shadowRadius: Set the shadow radius. If it is set to 0.1, it becomes the font color. Generally, it is better to set it to 3.0.
Android: singleLine: Set single row display. If it is used with layout_width, when the text cannot be fully displayed, "…" is used later. . For example, android: text = "test _ singleLine"
Android: singleLine = "true" android: layout_width = "20dp" only "t…" is displayed ...". If singleLine is not set or is set to false, the text will wrap automatically.
Android: text: Set to display text.
Android: textAppearance: Set the text appearance. Such as "? Android: attr/textAppearanceLargeInverse "refers to the appearance of the system ,? Indicates whether the system has this appearance. Otherwise, the default appearance is used. Configurable values: textAppearanceButton/textAppearanceInverse/textAppearanceLarge/textAppearanceLargeInverse/textAppearanceMedium/combine/textAppearanceSmall/textAppearanceSmallInverse
Android: textColor: set text color
Android: textColorHighlight: the background color of the selected text. The default value is blue.
Android: textColorHint: Set the color of the text in the prompt message. The default value is gray. Used with hint.
Android: textColorLink: text link color.
Android: textScaleX: Set the interval between texts. The default value is 1.0f.
Android: textSize: Set the text size. The recommended measurement unit is "sp", for example, "15sp"
Android: textStyle: Set the font [bold (bold) 0, italic (italic) 1, bolditalic (bold and oblique) 2] You can set one or more, separated by "|"
Android: typeface: Set the text font. It must be one of the following constant values: normal 0, sans 1, serif 2, monospace (same width font) 3]
Android: height: sets the height of the text area. supported measurement units: px (pixels)/dp/sp/in/mm (millimeters)
Android: maxHeight: sets the maximum height of the text area.
Android: minHeight: sets the minimum height of the text area.
Android: width: Set the width of the text area. The measurement unit is px (pixel)/dp/sp/in/mm (mm). The difference between the measurement unit and layout_width is shown here.
Android: maxWidth: sets the maximum width of the text area.
Android: minWidth: sets the minimum width of the text area.

PS: detailed explanation of length units in Android

The length units in Android are detailed (dp, sp, px, in, pt, mm). Many people do not quite understand the difference between dp, sp, and px: here we will introduce dp and sp. Dp is dip. This is basically similar to sp. You can use dp or sp to specify attributes such as length and height. If you set the font, you need to use sp. Dp is not related to density. sp is not only related to density, but also to scale. If the screen density is 160, dp and sp are the same as px. 1dp = 1sp = 1px, but if px is used as the unit, if the screen size remains unchanged (assuming it is still 3.2), the screen density is changed to 320. The original TextView width is set to 320 PX, And the 3.2-inch screen with a density of 160 is half shorter than the 3.2-inch screen with a density. But if it is set to 160dp or 160sp. The system automatically sets the width property value to 320px. That is, 160*320/160. Among them, 320/160 can be called the density proportion factor. That is to say, if dp and sp are used, the system will automatically convert according to the screen density change.

Meaning of other units
Px: the actual pixel of the screen. For example, 320*480 screens have 320 pixels horizontally and 480 pixels vertically.
In: indicates the inch, which is the physical size of the screen. Each inch equals 2.54 cm. For example, the screen size of a mobile phone is often described as 3.2 (English), 3.5 (English), and 4 (English. These dimensions are the diagonal length of the screen. If the phone screen is 3.2 inch, the diagonal line length of the phone screen (visible area) is 3.2*2.54 = 8.128 cm. You can measure your mobile phone screen to see if the size is the same as the actual size.
Mm: Indicates mm, which is the physical size of the screen.
Pt: indicates a point, which is the physical size of the screen. The size is 1 inch of 1/72.


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.