Android字体设置

原博客:http://www.cnblogs.com/bluestorm/p/3654626.html

// 自定义字体
custom = new TextView(this);
//xx.ttf located at assets/fonts/
typeface = Typeface.createFromAsset(getAssets(),"fonts/xx.ttf");
custom.setTypeface(typeface);

 

.自定义字体
1.android Typeface使用TTF字体文件设置字体

我们可以在程序中放入ttf字体文件,在程序中使用Typeface设置字体。
第一步,在assets目录下新建fonts目录,把ttf字体文件放到这。
第二步,程序中调用:
AssetManager mgr=getAssets();//得到AssetManager
Typeface tf=Typeface.createFromAsset(mgr, "fonts/ttf.ttf");//根据路径得到Typeface
tv.setTypeface(tf);//设置字体

 

 

2.在xml文件中使用android:textStyle=”bold” 可以将英文设置成粗体, 但是不能将中文设置成粗体, 
将中文设置成粗体的方法是: 
TextView tv = (TextView)findViewById(R.id.TextView01); 
tv.getPaint().setFakeBoldText(true);//中文仿“粗体”--使用TextPaint的仿“粗体”设置setFakeBoldText为true。

参考:
http://hi.baidu.com/spare_h/blog/item/490fa14d24325ce0d62afc34.html
http://hi.baidu.com/spare_h/blog/item/a8a20818cfde325c42a9ad49.html


xml 中 android:fontFamily 的用法

 

From android 4.1 / 4.2, the following Roboto font families are available:

android:fontFamily="sans-serif" // roboto regular
android:fontFamily="sans-serif-light" // roboto light
android:fontFamily="sans-serif-condensed" // roboto condensed
android:fontFamily="sans-serif-thin" // roboto thin (android 4.2)


android:fontFamily="sans-serif"           // roboto regular
android:fontFamily="sans-serif-light"     // roboto light
android:fontFamily="sans-serif-condensed" // roboto condensed
android:fontFamily="sans-serif-thin"      // roboto thin (android 4.2)
android:fontFamily="sans-serif-medium"    // roboto medium (android 5.0)

You can also use Typeface.create(). For example, Typeface.create("sans-serif-light", Typeface.NORMAL).


in combination with

android:textStyle="normal|bold|italic"
this 12 variants are possible:

Regular
Italic
Bold
Bold-italic
Light
Light-italic
Thin
Thin-italic
Condensed regular
Condensed italic
Condensed bold
Condensed bold-italic


android:fontFamily 与 android:typeface 相同
Android内建的字体有:
normal
sans
serif
monospace

详见:TextView | Android Developers
http://developer.android.com/reference/android/widget/TextView.html#attr_android%3atypeface

How to change fontFamily of TextView in Android - Stack Overflow
http://stackoverflow.com/questions/12128331/how-to-change-fontfamily-of-textview-in-android


Android System Fonts(/system/fonts):
AndroidClock.ttf
AndroidClock_Highlight.ttf
AndroidClock_Solid.ttf
AndroidEmoji.ttf
Clockopia.ttf
DroidNaskh-Regular.ttf
DroidNaskhUI-Regular.ttf
DroidSans-Bold.ttf
DroidSans.ttf
DroidSansArmenian.ttf
DroidSansEthiopic-Regular.ttf
DroidSansFallback.ttf
DroidSansGeorgian.ttf
DroidSansHebrew-Bold.ttf
DroidSansHebrew-Regular.ttf
DroidSansMono.ttf
DroidSerif-Bold.ttf
DroidSerif-BoldItalic.ttf
DroidSerif-Italic.ttf
DroidSerif-Regular.ttf
MTLmr3m.ttf
Roboto-Bold.ttf
Roboto-BoldItalic.ttf
Roboto-Italic.ttf
Roboto-Light.ttf
Roboto-LightItalic.ttf
Roboto-Regular.ttf
Roboto-Thin.ttf
Roboto-ThinItalic.ttf
RobotoCondensed-Bold.ttf
RobotoCondensed-BoldItalic.ttf
RobotoCondensed-Italic.ttf
RobotoCondensed-Regular.ttf


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值