• 自己定义TextView 调用ttf格式字体



    方法一:自己定义TextView 调用ttf格式字体

    <strong>将ttf格式文件存放在assets/fonts/下</strong>

    注:PC系统字体存放在C:WindowsFonts下

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

    方法二:

    Typeface typeface = Typeface.createFromAsset(getAssets(),"DS-DIGIT.TTF");
    		
    // 设置字体类型
    timeTextView.getPaint().setTypeface(typeface);


  • 相关阅读:
    csuoj-1004-Xi and Bo
    csuoj-1003-UC Browser
    网络命令
    linux网络配置
    java面向对象
    java类 面向对象
    java方法 Scanner、Random类
    java集合
    java数组
    java流程控制语句
  • 原文地址:https://www.cnblogs.com/slgkaifa/p/6758648.html
Copyright © 2020-2023  润新知