Tired with all the common fonts provided originally by Android code? Well, we can always do some alterations and bring some fun in it!
Default Font Types:
There are five font types provided by Android, DEFAULT, DEFAULT_BOLD, MONOSPACE, SANS_SERIF, and SERIF. In order to change the font style, one can add android:typeface attribute into the XML declaration file of the components that support font styling, TextView for instance.
Other Font Type:
Do not like any of these default font types? Wanna something different and eyes catching font? Sure, get the ttf file of the font you wanted, and place it in ./assets folder (normally it is auto generated when you create a new project, else, create one manually). In this example, I downloaded a font here, named JoeHand2. Since we are going to apply the custom font, we do not include android:typeface into the TextView declaration like what we did above.
Then in the onCreate() method, add the codes below:
Wanna change the font size? Sure you can, add android:textSize attribute into the XML file. There are several commonly used units, sp (scale pixels), px (pixels), dp (density-dependent pixels)
Font Style:
Surely we cannot forget one of the biggest attributes of a font, the typical font style, NORMAL, BOLD, and ITALIC. Add android:textStyle attribute, and the available values for this attributes is "normal", "bold", "italic". You can also specify "bold|italic" to apply two styles at once.
Font Color:
Sick with only black and white font colors? You can make a different too! Add android:textColor attribute!
Text Shadow:
Whenever I design with Photoshop, I am super thrilled with all the appearance properties provided by Photoshop. Though I had been complaint a lot about not to "shadow" everything, I just cant get enough!!
There are four properties used to customize the text shadow.
- android:shadowColor
- android:shadowRadius
- android:shadowDx
- android:shadowDy
Unlike FontSize attribute, these attributes do not require any specific unit
That's it!!! Now you can change the font properties whenever you like!!
No comments:
Post a Comment