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

Android为String中部分文字设置TTF字体

2015-09-11 15:05 501 查看
/**
	 * 代码描述:
	 * 为String中部分文字设置TTF字体
	 * 参考资料:
	 * 1 http://blog.csdn.net/lfdfhl/article/details/27372895 	 * 2 http://blog.csdn.net/lfdfhl/article/details/10898001 	 */
	private void testTypeface() {
		String str = "32.000000%";
		mTextView = (TextView) findViewById(R.id.textView);
		//Futura Condensed Medium.ttf为assets下的ttf文件
		String ttfPath="fonts/Futura Condensed Medium.ttf";
		Typeface mTypeface = Typeface.createFromAsset(getAssets(),ttfPath);
		SpannableString spannableString = new SpannableString(str);
		spannableString.setSpan(new TypefaceSpan(ttfPath), 1, 7,Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
		mTextView.setTypeface(mTypeface);
		mTextView.setTextSize(45);
		mTextView.setText(spannableString);
	}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: