Android系统默认支持三种字体,分别为:“sans”, “serif”, “monospace",除此之外还可以使用其他字体文件(*.ttf)
方法一:XML中使用android默认字体
<!-- 使用默认的sans字体-->
<TextView Android:id="@+id/sans"
Android:text="Hello,World"
Android:typeface="sans"
Android:textSize="20sp" />
<!-- 使用默认的serifs字体-->
<TextView Android:id="@+id/serif"
Android:text="Hello,World"
Android:typeface="serif"
Android:textSize="20sp" />
<!-- 使用默认的monospace字体-->
<TextView Android:id="@+id/monospace"
Android:text="Hello,World"
Android:typeface="monospace"
Android:textSize="20sp" />
方法二:在Android中可以引入其他字体,首先要将字体文件保存在assets/fonts/目录下
1. <!-- 这里没有设定字体,将在Java代码中设定-->
<TextView Android:id="@+id/custom"
Android:text="Hello,World"
Android:textSize="20sp" />
2. java程序中引入其他字体关键代码
//得到TextView控件对象
TextView textView =(TextView)findViewById(R.id.custom);
//将字体文件保存在assets/fonts/目录下,创建Typeface对象
Typeface typeFace =Typeface.createFromAsset(getAssets(),"fonts/HandmadeTypewriter.ttf");
//使用字体
textView.setTypeface(typeFace);
摘自:http://www.cnblogs.com/bravestarrhu/archive/2012/07/17/2595598.html
相关推荐
Android Typeface Helper,可以帮你轻松实现自定义字体的库,博客附件,效果请查看博客相对应项目。
我们可以在程序中放入ttf字体文件,在程序中使用Typeface设置字体。 第一步,在assets目录下新建fonts目录,把ttf字体文件放到这。 第二步,程序中调用: 代码如下:AssetManager mgr=getAssets();//得到...
TypefaceHelper, helper 对象,用于将字体注入到android的各种文本视图中 TypefaceHelper helper 对象,用于将字体注入到android的各种文本视图中。概述我们可以以为任何文本视图使用各种自定义字体资产,但是没有...
我们可以在程序中放入ttf字体文件,在程序中使用Typeface设置字体。 第一步,在assets目录下新建fonts目录,把ttf字体文件放到这。 第二步,程序中调用: AssetManager mgr=getAssets();//得到AssetMa
字体文本视图字体 TextView 允许您直接在 XML 中指定自定义字体,并避免创建字体样板代码。注意此库已弃用且不再维护。 请利用精彩的库来满足您所有的自定义字体需求。快速开始第 1 步 - 添加字体 TextView 作为库...
TextView中设置后无效果。 android:shadowColor指定文本阴影的颜色,需要与shadowRadius一起使用。效果: android:shadowDx设置阴影横向坐标开始位置。 android:shadowDy设置阴影纵向坐标开始位置。 ...
android 系统本身内置了一些字体,可以在程序中使用,并且支持在xml配置textView的时候进行修改字体的样式。支持字段为android:textStyle ,android:typeface, android:fontFamily,系统内置了normal|bold|italic三种...
通过findViewById找到view,然后一个个的去设置字体 Typeface customFont = Typeface.createFromAsset(this.getAssets(), "fonts/customFont.ttf"); TextView view = (TextView) findViewById(R.id.text); view....
Android实现新字体的引入(Typeface的使用)-附件资源
在Android SDK中使用Typeface类来定义字体,可以通过常用字体类型名称进行设置,如设置默认黑体: Paint mp = new paint(); mp.setTypeface(Typeface.DEFAULT_BOLD) 常用的字体类型名称还有: * Typeface.DEFAULT /...
Android Typeface Helper自定义字体库.rar,太多无法一一验证是否可用,程序如果跑不起来需要自调,部分代码功能进行参考学习。
Android Typeface Helper自定义字体库.rar,太多无法一一验证是否可用,程序如果跑不起来需要自调,部分代码功能进行参考学习。
Android 开发人员为 TextViews 设置字体样式的简单方法 这个开发小片段应该可以帮助开发者为 TextView/TextViews 设置字体,并且减轻总是试图调用Typeface.createFromAsset(....);的压力Typeface.createFromAsset(.....
在 Android 中,若需要使得某个TextView加载字体包,使用以下方式即可: Typeface typeFace =Typeface.createFromAsset(getAssets(),fonts/Bold.otf); textView.setTypeface(typeFace); 至于字体包的位置: 通过...
ttf文件放入assets文件夹中;调用字体* 字体样式* TextView设置xml中typeface类型只有4种:monospace\normal\sans
CustomTypeface 是一个 Android 库,用于将自定义字体设置为视图。 我们以 OpenSans 为例,但您可以修改此库并使用您喜欢的任何字体。 #用法 您应该扩展要设置字体的视图,如下所示: public class ...
3、在布局文件中添加textView组件,设置android:text属性 @string/xxx,xxx代表fontstrings中的name名称 android:id="@+id test" android:text="@string/tint20" /> 4、Activity中进行如下设置 Typeface font= ...