TextView
to control:TextView
is positioned in a layout (like any other view)TextView
itself appears, such as with a background colorTextView
, such as the initial text and its style, size, and colorhello_world
) that's easier to maintain for multiple-language versions of the app, or if you need to change the string in the future. After extracting the string, use the string resource name with @string/
to specify the text:android:layout_width
and android:layout_height
(which are required for a TextView
), the most often used attributes with TextView
are the following:android:textColor
: Set the color of the text. You can set the attribute to a color value, a predefined resource, or a theme. Color resources and themes are described in other chapters.android:textAppearance
: The appearance of the text, including its color, typeface, style, and size. You set this attribute to a predefined style resource or theme that already defines these values.android:textSize
: Set the text size (if not already set by android:textAppearance
). Use sp
(scaled-pixel) sizes such as 20sp
or 14.5sp
, or set the attribute to a predefined resource or theme.android:textStyle
: Set the text style (if not already set by android:textAppearance
). Use normal
, bold
, italic
, or bold
|italic
.android:typeface
: Set the text typeface (if not already set by android:textAppearance
). Use normal
, sans
, serif
, or monospace
.android:lineSpacingExtra
: Set extra spacing between lines of text. Use sp
(scaled-pixel) or dp (device-independent pixel) sizes, or set the attribute to a predefined resource or theme.android:autoLink
: Controls whether links such as URLs and email addresses are automatically found and converted to clickable (touchable) links.android:autoLink
:none
: Match no patterns (default).web
: Match web URLs.email
: Match email addresses.phone
: Match phone numbers.map
: Match map addresses.all
: Match all patterns (equivalent to web|email|phone|map).android:autoLink="web"
.TextView
in your Java code, use its resource id
. For example, to update a TextView
with new text, you would:TextView
and assign it to a variable. You use the findViewById()
method of the View
class, and refer to the view you want to find using this format:show_count
) :View
as a TextView
member variable, you can then set the text to new text (in this case, mCount_text
) using the setText()
method of the TextView
class: