Android text decoration


Android provide attributes that can be use to decorate text. These text decoration attributes can be applied to several views like:

  • TextView
  • EditText
  • Button
  • RadioButton
  • CheckBox
  • ListView
  • GridView

Let's discuss it one by one:

Typeface


There are 4 fonts known as Droid family of fonts are:

  • monospace
  • sans
  • serif
  • normal

We can use one of droid family of font as a value of android:typeface

Here is how it looks like

android:typeface

Font family


android:fontFamily can have one of these font family as it's value.

  • monospace
  • casual
  • cursive
  • sans-serif
  • sans-serif-condensed
  • sans-serif-smallcaps
  • serif
  • serif-monospace

Here is how it looks like

android:fontFamily

Text Style


The android:textStyle attribute can be used to emphasize a text. Possible values of android:textStyle is:

  • bold
  • italic
  • normal

Here is how it looks like

android:textStyle

Text Size


android:textSize specifies the font size. Its value must consist of two parts: a floating-point number followed by a unit. It is a good practice to use sp unit so that the size can scale depending on user settings.

Here is how it looks like

android:textSize

Text Color


android:textColor uses to add color in text of a view.

Here is how it looks like

android:textColor

We also can change text color at runtime: Here is example

Text Shadow


Here is different attributes that can be used customize the appearance of text shadow:

  • android:shadowColor - Shadow color in the same format as textColor.
  • android:shadowRadius - Radius of the shadow specified as a floating point number.
  • android:shadowDx - The shadow's horizontal offset specified as a floating point number.
  • android:shadowDy - The shadow's vertical offset specified as a floating point number.

android:shadowColor

How to enable selection?


The textIsSelectable flag allows users to make selection gestures in the TextView, which in turn triggers the system's built-in copy/paste controls.

To allow users to copy some or all of the view's value and paste it somewhere else, set the XML attribute android:textIsSelectable to "true" or call setTextIsSelectable(true).

Result


android:textIsSelectable

Share & Like

Tutorial topics

About ApnaTutorials.com

ApnaTutorials.com is for Java, J2ee, Html5 and android developers. All tutorials are well explained and are easy to understand. We have tested every tutorials on our developement environment before posting it in public domain.