The simplest widget is the label, referred to in Android as a TextView.
As in most GUI toolkits, labels are bits of text that can't be edited
directly by users. Typically, labels are used to identify adjacent
widgets (e.g., a "Name:" label next to a field where the user fills in a
name).
In Java, you can create a label by creating a TextView instance. More commonly, though, you will create labels in XML layout files by adding a TextView element to the layout, with an android:text
property to set the value of the label itself. If you need to swap
labels based on certain criteria, such as internationalization, you may
wish to use a string resource reference in the XML instead.
TextView has numerous other properties of relevance for labels, such as the following:
android:typeface: Sets the typeface to use for the label (e.g., monospace)
android:textStyle: Indicates that the typeface should be made bold (bold), italic (italic), or bold and italic (bold_italic)
android:textColor: Sets the color of the label's text, in RGB hex format (e.g., #FF0000 for red)
For example, in the Basic/Label project, you will find the following layout file:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="You were expecting something profound?"
/>
Just that layout alone, with the stub Java source provided by Android's project builder (e.g., android create project), gives you the result shown in Figure 1.