美文网首页
Android字体

Android字体

作者: 陈大集 | 来源:发表于2015-10-19 14:58 被阅读253次

Android系统默认了三种字体
sans
serif
monospace

可以通过下面的方式设置字体

<!--  使用默认的sans字体-->        
<TextView    
  android:id="@+id/sans"                   
  android:text="Hello,World"                   
  android:typeface="sans"                   
  android:textSize="20sp" />

如果上面三种字体都不符合要求,可以通过

1.在assets/fonts/目录下添加字体文件,如*.ttf
2.在Java代码中进行设置

//得到TextView控件对象        

TextView textView =(TextView)findViewById(R.id.custom);

//将字体文件保存在assets/fonts/目录下,创建Typeface对象
Typeface typeFace =Typeface.createFromAsset(getAssets(),"fonts/HandmadeTypewriter.ttf");
//使用字体
textView.setTypeface(typeFace);

相关文章

网友评论

      本文标题:Android字体

      本文链接:https://www.haomeiwen.com/subject/kevzcttx.html