Pr.Pg Next Pg

Formatting the Text tutorials

  • We can format the text i.e. resizing the text, adding colors etc. by using the appropriate attributes.

 

 

Following are the different dimensions for specifying the sizes of the text.

 

  • Density-independent Pixels (dp) - An abstract unit that is based on the physical density of the screen. These units are relative to a 160 dpi (dots per inch) screen, on which 1dp is roughly equal to 1px. When running on a higher density screen, the number of pixels used to draw 1dp is scaled up by a factor appropriate for the screen's dpi.

 

  • Scale-independent Pixels (sp) - This is like the dp unit, but it is also scaled by the user's font size preference. It is recommend you use this unit when specifying font sizes, so they will be adjusted for both the screen density and the user's preference.

 

  • Points (pt) - 1/72 of an inch based on the physical size of the screen.

 

  • Pixels (px) - Corresponds to actual pixels on the screen. This unit of measure is not recommended because the actual representation can vary across devices; each devices may have a different number of pixels per inch and may have more or fewer total pixels available on the screen.

 

  • Millimeters (mm) - Based on the physical size of the screen.

 

  • Inches (in) - Based on the physical size of the screen.

 

  • Thus after adding the size attribute to the text like android:textSize="40sp", the screen will look like this

 

 

Pr.Pg border                                              Next Pg