devstory

Le Tutoriel de Android TextView

View more Tutorials:

Site d'apprentissage des langues gratuit:
Suivez-nous sur notre fanpage pour recevoir des notifications chaque fois qu'il y a de nouveaux articles. Facebook

1- Android TextView

Sous Android, TextView est un contrôle d'interface utilisateur (User Interface Control) permettant d'afficher le texte. Cela ressemble à une étiquette (Label). Par défaut, l'utlisateur n'a pas le droit de modifier le contenu du texte.

2- TextView Attributes

Attribute Description
android:id It is used to uniquely identify the control
android:autoLink It will automatically found and convert URL(s) and email addresses as clickable links.
android:ems It is used to make the TextView be exactly this many ems wide.
android:hint It is used to display the hint text when text is empty
android:width It makes the TextView be exactly this many pixels wide.
android:height It makes the TextView be exactly this many pixels tall.
android:text It is used to display the text.
android:textColor It is used to change the color of the text.
android:gravity It is used to specify how to align the text by the view's x and y-axis.
android:maxWidth It is used to make the TextView be at most this many pixels wide.
android:minWidth It is used to make the TextView be at least this many pixels wide.
android:textSize It is used to specify the size of the text.
android:textStyle It is used to change the style (bold, italic, bolditalic) of text.
android:textAllCaps It is used to present the text in all CAPS.
android:typeface It is used to specify the Typeface (normal, sans, serif, monospace) for the text.
android:textColorHighlight It is used to change the color of text selection highlight.
android:textColorLink It is used to change the text color of links.
android:inputType It is used to specify the type of text being placed in text fields.
android:fontFamily It is used to specify the fontFamily for the text.
android:editable If we set, it specifies that this TextView has an input method.
android:autoLink
Cet attribut demande à Android de créer automatiquement des liens (links) pour les numéros de téléphone, les adresses, les emails et les adresses de sites web recencés dans le texte de TextView.
Constant Value Description
all f Match all patterns (equivalent to web|email|phone|map).
email 2 Match email addresses.
map 8 Match map addresses.
none 0 Match no patterns (default).
phone 4 Match phone numbers.
web 1 Match Web URLs

<TextView
    android:id="@+id/textView_a11"
    android:autoLink="email|phone|map|web"
    android:textColorLink="#FF0000"
    android:text="Contact: +1-1111222233, [email protected]. http://abc.com, 620 Eighth Avenue New York, NY 10018"
    ... />
Click on Phone Link.
Click on Email Link
Click on Web URL
Click on Address Link (Will open Google Map)
android:ems
Cet attribut est utilisé pour spécifier une valeur de la largeur de TextView selon les unités d'EM. EM est une unité en Typography (Typographie) dont la valeur correspond à la largeur de la lettre "M".
Ainsi, android:ems="5" signifie qu'il définit la largeur pour TextView à 5 fois plus que celle de la lettre "M".
android:text
Spécifier le contenu du texte pour TextView.
android:textColor
Spécifier la couleur du texte pour TextView.
android:textSize
Spécifier la taille de police du texte.
android:textStyle
Spécifier un style pour la police qui dispose de quatre valeurs:
  1. android:textStyle="normal"  (Default)
  2. android:textStyle="bold"
  3. android:textStyle="italic"
  4. android:textStyle="bold|italic"
android:textAllCaps
Cet attribut comporte deux valeurs, true/false. Avec la valeur true, le texte de TextView est affiché en majuscule. Sa valeur par défaut est false.
android:textColorHighlight
Définir la couleur d'arrière-plan du sous-texte sélectionné. Cet attribut est utile quand vous utilisez EditText (une sous-classe de TextView). EditText permet à l'utilisateur de sélectionner et de modifier son texte.
android:textColorLink
Spécifier la couleur de police des liens dans le texte. (En savoir plus sur l'attribut android:autoLink).
android:fontFamily
Spécifier font family (la famille de police) pour le texte de TextView.
android:editable

View more Tutorials: