Friday, 30 September 2016

android - How to change the font on the TextView?



How to change the font in a TextView, as default it's shown up as Arial? How to change it to Helvetica?


Answer



First, the default is not Arial. The default is Droid Sans.




Second, to change to a different built-in font, use android:typeface in layout XML or setTypeface() in Java.



Third, there is no Helvetica font in Android. The built-in choices are Droid Sans (sans), Droid Sans Mono (monospace), and Droid Serif (serif). While you can bundle your own fonts with your application and use them via setTypeface(), bear in mind that font files are big and, in some cases, require licensing agreements (e.g., Helvetica, a Linotype font).



EDIT




The Android design language relies on traditional typographic tools
such as scale, space, rhythm, and alignment with an underlying grid.

Successful deployment of these tools is essential to help users
quickly understand a screen of information. To support such use of
typography, Ice Cream Sandwich introduced a new type family named
Roboto, created specifically for the requirements of UI and
high-resolution screens.



The current TextView framework offers Roboto in thin, light, regular
and bold weights, along with an italic style for each weight. The
framework also offers the Roboto Condensed variant in regular and bold
weights, along with an italic style for each weight.





After ICS, android includes Roboto fonts style,
Read more Roboto



EDIT 2




With the advent of Support Library 26, Android now supports custom fonts by
default. You can insert new fonts in res/fonts which can be set to TextViews individually either in XML or programmatically. The default font for the whole application can also be changed by defining it styles.xml The android developer documentation has a clear guide on this here




No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...