android开发分享Android字体设置及Roboto字体使用方法

本文实例讲述了android字体设置及roboto字体使用方法。分享给大家供大家参考。具体分析如下: 一、自定义字体 1.android typeface使用ttf字体

android开发分享Android字体设置及Roboto字体使用方法实例讲述了android字体设置及roboto字体使用方法。分享给大家供大家参考。具体分析如下:

上述就是android开发分享Android字体设置及Roboto字体使用方法的全部内容,如果对大家有所用处且需要了解更多关于Android学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!

一、自定义字体

1.android typeface使用ttf字体文件设置字体

我们可以在程序中放入ttf字体文件,在程序中使用typeface设置字体。
第一步,在assets目录下新建fonts目录,把ttf字体文件放到这。
第二步,程序中调用:

复制代码 代码如下:
assetmanager mgr=getassets();//得到assetmanager
typeface tf=typeface.createfromasset(mgr, “fonts/ttf.ttf”);//根据路径得到typeface
tv=findviewbyid(r.id.textview);
tv.settypeface(tf);//设置字体

2.在xml文件中使用android:textstyle=”bold” 可以将英文设置成粗体, 但是不能将中文设置成粗体,
将中文设置成粗体的方法是:

复制代码 代码如下:
textview tv = (textview)findviewbyid(r.id.textview01);  
tv.getpaint().setfakeboldtext(true);//中文仿“粗体”–使用textpaint的仿“粗体”设置setfakeboldtext为true。

注意:部分字体中文无效,虽然不会报错,但是对中文无效。

二、使用roboto

自从android4.0后默认字体就使用了roboto,下面介绍一下使用方法:

复制代码 代码如下:
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”

可用的参数如下:

regular
italic
bold
bold-italic
light
light-italic
thin
thin-italic
condensed regular
condensed italic
condensed bold
condensed bold-italic

希望android开发分享Android字体设置及Roboto字体使用方法所述对大家的android程序设计有所帮助。

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/addevelopment/940702.html

(0)
上一篇 2021年11月13日
下一篇 2021年11月13日

精彩推荐