Android字体设置,Roboto字体使用
一、自定义字体
1.android Typeface使用TTF字体文件设置字体
我们可以在程序中放入ttf字体文件,在程序中使用Typeface设置字体。
第一步,在assets目录下新建fonts目录,把ttf字体文件放到这。
第二步,程序中调用:
[java]view plaincopy
AssetManagermgr=getAssets();//得到AssetManager
Typefacetf=Typeface.createFromAsset(mgr,"fonts/ttf.ttf");//根据路径得到Typeface
tv=findViewById(R.id.textview);
tv.setTypeface(tf);//设置字体
2.在xml文件中使用android:textStyle=”bold” 可以将英文设置成粗体, 但是不能将中文设置成粗体,
将中文设置成粗体的方法是:
[java]view plaincopy
TextViewtv=(TextView)findViewById(R.id.TextView01);
tv.getPaint().setFakeBoldText(true);//中文仿“粗体”--使用TextPaint的仿“粗体”设置setFakeBoldText为true。
注意:部分字体中文无效,虽然不会报错,但是对中文无效。
二、使用RoBoto
自从Android4.0后默认字体就使用了Roboto,下面介绍一下使用方法:
[java]view plaincopy
android:fontFamily="sans-serif"//robotoregular
android:fontFamily="sans-serif-light"//robotolight
android:fontFamily="sans-serif-condensed"//robotocondensed
android:fontFamily="sans-serif-thin"//robotothin(android4.2)
//incombinationwith
android:textStyle="normal|bold|italic"
可用的参数:
Regular
Italic
Bold
Bold-italic
Light
Light-italic
Thin
Thin-italic
Condensed regular
Condensed italic
Condensed bold
Condensed bold-italic
其他精彩文章文章
Android KSOAP2调用.net webservice
jQuery教程(8)-DOM树操作之使用反向插入方法
android学习笔记(34)使用AlertDialog创建简单对话框
android学习笔记(33)画廊视图(Gallery)的功能和用法
android navidgation drawer 在导航抽屉中如何改变List选中项的...
更多关于android开发文章
更多相关文章
- Android(安卓)5.x theme: AppCompatActivity与toolbar的结合
- Android(安卓)Studio 4.0 设置代理proxy和maven
- 使用Vitamio打造自己的Android万能播放器(2)—— 手势控制亮度、音
- 【Android(安卓)Developers Training】 36. 设置文件共享
- android开发教程之listview使用方法
- 轻松使用xmlpull解析xml
- Android(安卓)theme 使用
- Android下在onCreate方法中获取TextView的高度
- Android在一个app中启动其他app中的service或者Activity