Android使用第三方字体

很多时候,Android系统自带的字体可能和我们的APP风格不符。这时候,我们就需要下载并使用第三方字体了。

Android中使用第三方字体,需先下载字体库,一般后缀名为 .ttf (百度上可以找到很多)

Android开发中使用方法:

1.在 asset 目录下,新建fonts文件夹,用于存放字体文件,并将需要使用的字体文件放入该文件夹


2. 给TextView设置字体

		TextView tv1 = (TextView) findViewById(R.id.textView1);
		Typeface typeFace = Typeface.createFromAsset(getAssets(),"fonts/xing_kai.ttf");
		tv1.setTypeface(typeFace);


3.自定义控件中,给paint设置字体

(context 一般在构造方法中传入)

		AssetManager mgr=context.getAssets();//得到AssetManager  
		Typeface typeface=Typeface.createFromAsset(mgr, "fonts/xing_kai.ttf");//根据路径得到Typeface  
		paint.setTypeface(typeface);  


用法很简单,就不上传项目了




猜你喜欢

转载自blog.csdn.net/qq_34763699/article/details/78696039