当前位置: 代码迷 >> Android >> Android中内嵌字体兑现个性化
  详细解决方案

Android中内嵌字体兑现个性化

热度:31   发布时间:2016-05-01 16:24:50.0
Android中内嵌字体实现个性化
Android的Assets类有单个文件1MB体积的限制,将字体文件test.ttf放到工程的assets文件夹的fonts目录中。



package org.yftx.font;import android.app.Activity;import android.graphics.Color;import android.graphics.Typeface;import android.os.Bundle;import android.widget.TextView;public class MainAcitity extends Activity {	@Override	public void onCreate(Bundle savedInstanceState) {		super.onCreate(savedInstanceState);		setContentView(R.layout.main);		Typeface textFont = Typeface.createFromAsset(getAssets(), "fonts/test.ttf");		TextView testView = (TextView) findViewById(R.id.textView2);		testView.setTypeface(textFont); // 设置TextView的风格		testView.setTextSize(12);		testView.setTextColor(Color.RED);	}}
  相关解决方案