首页 > 代码库 > 自定义TextView 调用ttf格式字体
自定义TextView 调用ttf格式字体
自定义TextView 调用ttf格式字体
<strong>将ttf格式文件存放在assets/fonts/下</strong>
注:PC系统字体存放在C:\Windows\Fonts下
import android.content.Context; import android.graphics.Typeface; import android.util.AttributeSet; import android.widget.TextView; /** * 修改字体 * */ public class MyTextView extends TextView { public MyTextView(Context context) { super(context); } public MyTextView(Context context, AttributeSet attrs) { super(context, attrs); changeTypeFace(context, attrs); } /** * 改变字体类型 * @param context * @param attrs */ private void changeTypeFace(Context context, AttributeSet attrs) { if (attrs != null) { //TypedArray a = context.obtainStyledAttributes(attrs, //R.styleable.TextView_Typefaces); // tf = a.getInt(R.styleable.TextView_Typefaces_tf, tf); Typeface mtf = Typeface.createFromAsset(context.getAssets(), "fonts/UnidreamLED.ttf"); super.setTypeface(mtf); } } }
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。