roboto字体android,Android字体设置 Roboto字体使用
一、自定義字體
1.android Typeface使用TTF字體文件設置字體
我們可以在程序中放入ttf字體文件,在程序中使用Typeface設置字體。
第一步,在assets目錄下新建fonts目錄,把ttf字體文件放到這。
第二步,程序中調用:
1.
AssetManager mgr=getAssets();//得到AssetManager
2.
3.
Typeface tf=Typeface.createFromAsset(mgr,"fonts/ttf.ttf");//根據路徑得到Typeface
4.
5.
tv=findViewById(R.id.textview);
6.
7.
tv.setTypeface(tf);//設置字體
2.在xml文件中使用android:textStyle=”bold” 可以將英文設置成粗體, 但是不能將中文設置成粗體,
將中文設置成粗體的方法是:
1.
TextView tv = (TextView)findViewById(R.id.TextView01);
2.
tv.getPaint().setFakeBoldText(true);//中文仿“粗體”--使用TextPaint的仿“粗體”設置setFakeBoldText為true。
注意:部分字體中文無效,雖然不會報錯,但是對中文無效。
二、使用RoBoto
自從
Android
4.0后默認字體就使用了Roboto,下面介紹一下使用方法:
1.
android:fontFamily="sans-serif"?// roboto regular
2.
android:fontFamily="sans-serif-light"?// roboto light
3.
android:fontFamily="sans-serif-condensed"?// roboto condensed
4.
android:fontFamily="sans-serif-thin"?// roboto thin (android 4.2)
5.
//in combination with
6.
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
在開發中可能會涉及到對于組件的字體或文本的字體的修改,可以通過Spannable來進行修改:
01.
TextView tv =new?TextView(this);
02.
tv.setText("字體大小進行設置");
03.
//創建Spannable 對象
04.
Spannable? span =new?SpannableString(tv.getText());
05.
/*通過setSpan(Object ,int start,int end,int flag)對特定的內容進行設置
06.
其中 AbsoluteSizeSpan 是決定字體大小
07.
*/
08.
span.setSpan(new?AbsoluteSizeSpan(11),0,2,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
09.
span.setSpan(new?AbsoluteSizeSpan(21),3,6,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
10.
11.
tv.setText(span);
總結
以上是生活随笔為你收集整理的roboto字体android,Android字体设置 Roboto字体使用的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【OS学习笔记】二十二 保护模式六:保户
- 下一篇: 【OS学习笔记】二十九 保护模式八:任务