`
hklongshao
  • 浏览: 72375 次
  • 性别: Icon_minigender_1
  • 来自: 苏州
社区版块
存档分类
最新评论

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);
	}
}



分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics