您的位置:首页 > 移动开发 > Android开发

android 自定义字体ttf使用的几种方法

2014-12-10 17:16 169 查看
1、首先来说下两种创建方式

(1) 这种要放在assets文件夹下

Typeface typeface = Typeface.createFromAsset(getContext().getAssets(),"fonts/font.ttf");



(2) 而这种是指定路径的

<pre name="code" class="java">Typeface typeface = Typeface.createFromFile("/mnt/sdcard/font.ttf");



2、使用方法

(1)textview字体设置

  TextView tv = (TextView)findViewById(R.id.TextView01); 
  tv.setTypeface(typeface);


(2)Canvas上写字字体设置


Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setTypeface(typeface);
anvas.drawText(str , rect.left , rect.top+height , paint);



                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: