如何更改 TextView 上的字体? [英] How to change the font on the TextView?

查看:22
本文介绍了如何更改 TextView 上的字体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何更改 TextView 中的字体,默认情况下它显示为 Arial?如何将其更改为 Helvetica?

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

推荐答案

首先,默认不是 Arial.默认为 Droid Sans.

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

其次,要更改为不同的内置字体,请在布局 XML 中使用 android:typeface 或在 Java 中使用 setTypeface().

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

第三,Android 中没有 Helvetica 字体.内置选项是 Droid Sans (sans)、Droid Sans Mono (monospace) 和 Droid Serif (serif).虽然您可以将自己的字体与您的应用程序捆绑在一起并通过 setTypeface() 使用它们,但请记住字体文件很大,并且在某些情况下需要许可协议(例如,Helvetica,Linotype 字体).

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).

编辑

Android 设计语言依赖于传统的排版工具例如比例、空间、节奏和与底层网格的对齐.成功部署这些工具对于帮助用户至关重要快速了解一屏信息.为了支持这种使用排版,冰淇淋三明治引入了一个名为Roboto,专为 UI 和高分辨率屏幕.

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.

当前的 TextView 框架以薄、轻、规则的方式提供 Roboto和粗体字重,以及每个字重的斜体样式.这框架还提供了常规和粗体的 Roboto Condensed 变体权重,以及每个权重的斜体样式.

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.

ICS 之后,android 包含 Roboto 字体样式,阅读更多Roboto

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

编辑 2

随着 Support Library 26 的出现,Android 现在支持自定义字体默认.您可以在 res/fonts 中插入新字体,这些字体可以在 XML 中或以编程方式单独设置为 TextViews.整个应用程序的默认字体也可以通过定义它的styles.xml 来更改Android 开发者文档对此有明确的指南 这里

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

这篇关于如何更改 TextView 上的字体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆