TextView - An Android View

TextView is a view class which extends View.java class. This view is part of the Android framework which provides out of box functionality to display the text to the user. Generally used to show informational data to the user i.e they are not editable by the user.

Known direct subclasses

Button, CheckedTextView, Chronometer, DigitalClock, EditText, TextClock

There are many attributes available to use in TextView, a few of them defined specifically for TextView and remaining inherited from the View class. So it becomes very difficult to remember all of them and so the simplistic way to make sure they can be used when you need them is to assume that your requirement can be satisfied with one of these attributes.

We are going discuss a few commonly used attributes:

android:textAppearance

  • Set using a style or theme attribute.
  • Specifies text color, typeface, size and style of the component.
  • Syntax:
    • “@[+][package:]type/name” —> android:textAppearance = “@style/TextViewStyle”
    • “?[package:]type/name" —> android:textAppearance=“?android:textAppearanceMedium”

android:textSize

  • Set using an integer or float values with recommend unit is sp (scaled-pixels). Other units allowed are px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), and mm (millimeters).
  • Specifies size to the text displayed
  • For e.g android:textSize="14.5sp"

android:textStyle

  • Set using predefined keywords - bold, italic, normal. Can also used combination of these keywords
  • Specifies the styles of the text shown.
  • For e.g android:textStyle="bold"

android:textColor

  • Set using a type resource, theme attribute or color value.
  • Specifies the text color of the text visible
  • Syntax:
    • “@[+][package:]type/name” —> android:textColor = “@color/black”
    • “?[package:]type/name" —> android:textColor =“?android:colorError”
    • "#rgb", "#argb", "#rrggbb", or “#aarrggbb" —> android:textColor =“#000000”

android:text

  • Set using string values. Can work with escape character as well.
  • Specifies the text to be shown

Resources

https://developer.android.com/reference/android/R.styleable#TextView

Comments

Popular posts from this blog

Fragment Lifecycle

AndroidManifest

Activity Lifecycle