android 字体样式

 

  前些天,弄了个小程序.总觉得他Y的手机字体太难看.然后在网上死命的查.原来方法贼简单.差点被忽悠去替换系统文件.废话不说.上程序代码片段.

  在贴代码之前,请你注意2点:

  1.你的手机最好是1500¥以上的,.因为好点的手机更加兼容你导入的字体.如果你的手机没有显示你的字体,也没有报错,恭喜你,你的手机out了.

  2.你导入的文件名称必须是字母,不能中文.而且你的字体文件必须放在你项目的  assets/fonts 下面.

 

 

		TextView titleView=new TextView(this);
		
	  	Typeface face = Typeface.createFromAsset(getAssets(),"fonts/DS.ttf");
		titleView.setText("我显示");//
		titleView.setTypeface(face);
 

 

代码很简单.下面给个封装类.

 

import android.app.Activity; 
import android.content.Context; 
import android.graphics.Canvas; 
import android.graphics.Color; 
import android.graphics.Paint; 
import android.graphics.Typeface; 
import android.os.Bundle; 
import android.view.View; 

/**
 * 
*    
* 项目名称:mip   
* 类名称:Typefaces   
* 类描述: 字体样式
* 创建人:JIE
* 创建时间:2011-12-29 上午11:51:05   
* 修改人:Administrator   
* 修改时间:2011-12-29 上午11:51:05   
* 修改备注:   
* @version    
*
 */
public class Typefaces extends Activity 
{ 
	/** Called when the activity is first created. */ 
	@Override 
	public void onCreate(Bundle savedInstanceState) 
	{ 
		super.onCreate(savedInstanceState); 
	
		setContentView(new SampleView(this)); 
	} 
	
	private static class SampleView extends View 
	{ 
		private Paint mPaint = new Paint(Paint.ANTI_ALIAS_FLAG); 
		private Typeface mFace; 
	
		public SampleView(Context context) 
		{
			super(context); 
			//实例化自定义字体 
			mFace = Typeface.createFromAsset(getContext().getAssets(),"fonts/a.ttf"); 
			//设置字体大小 
			mPaint.setTextSize(18); 
		} 
		
		@Override 
		protected void onDraw(Canvas canvas) 
		{
			canvas.drawColor(Color.WHITE); 
//			//绘制默认字体 
//			mPaint.setTypeface(null); 
//			canvas.drawText("Default:abcdefg", 10, 100, mPaint); 
			//绘制自定义字体 
			mPaint.setTypeface(mFace); 
			canvas.drawText("Custom:abcdefg", 10, 200, mPaint); 
		} 
	}
}
 

 

  本来附上字体的,但是网速贼慢.大伙自己去下把.要的,可以留个邮箱.

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值