Wednesday 22 November 2017

android - How to change the font on the TextView?

itemprop="text">

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


class="post-text" itemprop="text">
class="normal">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., href="http://www.linotype.com/526/helvetica-family.html" rel="noreferrer">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 href="http://developer.android.com/design/style/typography.html"
rel="noreferrer">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 href="https://developer.android.com/guide/topics/ui/look-and-feel/fonts-in-xml.html"
rel="noreferrer">here





No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...