欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android字體設(shè)置及Roboto字體使用方法

 更新時(shí)間:2015年01月19日 14:54:53   投稿:shichen2014  
這篇文章主要介紹了Android字體設(shè)置及Roboto字體使用方法,較為詳細(xì)的分析了自定義字體及RoBoto的具體用法,非常具有實(shí)用價(jià)值,需要的朋友可以參考下

本文實(shí)例講述了Android字體設(shè)置及Roboto字體使用方法。分享給大家供大家參考。具體分析如下:

一、自定義字體

1.android Typeface使用TTF字體文件設(shè)置字體

我們可以在程序中放入ttf字體文件,在程序中使用Typeface設(shè)置字體。
第一步,在assets目錄下新建fonts目錄,把ttf字體文件放到這。
第二步,程序中調(diào)用:

復(fù)制代碼 代碼如下:
AssetManager mgr=getAssets();//得到AssetManager
Typeface tf=Typeface.createFromAsset(mgr, "fonts/ttf.ttf");//根據(jù)路徑得到Typeface
tv=findViewById(R.id.textview);
tv.setTypeface(tf);//設(shè)置字體

2.在xml文件中使用android:textStyle=”bold” 可以將英文設(shè)置成粗體, 但是不能將中文設(shè)置成粗體,
將中文設(shè)置成粗體的方法是:

復(fù)制代碼 代碼如下:
TextView tv = (TextView)findViewById(R.id.TextView01);  
tv.getPaint().setFakeBoldText(true);//中文仿“粗體”--使用TextPaint的仿“粗體”設(shè)置setFakeBoldText為true。

注意:部分字體中文無效,雖然不會(huì)報(bào)錯(cuò),但是對(duì)中文無效。

二、使用RoBoto

自從Android4.0后默認(rèn)字體就使用了Roboto,下面介紹一下使用方法:

復(fù)制代碼 代碼如下:
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) 
//in combination with 
android:textStyle="normal|bold|italic"

可用的參數(shù)如下:

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

希望本文所述對(duì)大家的Android程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論