app 要求字体使用楷体,使用字体包

本文详细介绍了如何在Android应用中使用自定义字体的方法。包括字体文件的下载与存放位置、通过代码为特定TextView设置字体样式及全局应用自定义字体的具体实现步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1,下载字体包     http://www.3987.com/xiazai/6/fonts/36616.html#down

2.  studio中src\main\创建assets\fonts,存放字体包

3.  两种使用方法:

       <1.只是app中某一块需要使用特定的字体:

     TextView tv= (TextView) findViewById(R.id.tv);
Typeface face= Typeface.createFromAsset(getAssets(), "fonts/kaiti.ttf");
tv.setTypeface(face);

      <2.整个app字体都要使用特定字体:

          这种情况下如果还用第一种方法给每个TextView设置Typeface 就太麻烦了;

          这种情况下可用用自定义控件继承,TextView ,在控件中初始化设置TypeView;

          

package com.example.harvey.frontpagedemo.view;

import android.content.Context;
import android.content.res.AssetManager;
import android.graphics.Typeface;
import android.util.AttributeSet;
import android.widget.TextView;

/**
* Created by Harvey on 2016/4/15.
*/
public class CustomFontTextView extends TextView{
public CustomFontTextView(Context context) {
super(context);
init(context);
}
public CustomFontTextView(Context context, AttributeSet attrs) {
super(context, attrs);
init(context);
}
public CustomFontTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init(context);
}

private void init(Context context) {
AssetManager assetManager= context.getAssets();
Typeface typeface=Typeface.createFromAsset(assetManager, "fonts/kaiti.ttf");//楷体
// Typeface typeface=Typeface.createFromAsset(assetManager, "fonts/shoujin.ttf");//瘦金体
// Typeface typeface=Typeface.createFromAsset(assetManager,"fonts/fangzhengguli.ttf");//方正古隶
// Typeface typeface=Typeface.createFromAsset(assetManager,"fonts/jinglei.ttf");//方正静蕾简体
// Typeface typeface=Typeface.createFromAsset(assetManager,"fonts/pop.ttf");//pop字体
setTypeface(typeface);
}


}

 4.  字体包不小......             


 

转载于:https://www.cnblogs.com/donghaifeng-2016/p/5395262.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值