zoukankan      html  css  js  c++  java
  • 自己定义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);


  • 相关阅读:
    贪心:SPOJ Backup Files
    杂题 SPOJ MOBILE2
    杂题 UVAoj 10000 Longest Paths
    杂题 UVAoj 107 The Cat in the Hat
    DP(斜率优化):HDU 3507 Print Article
    搜索(DLX): POJ 3074 3076 Sudoku
    DLX模板
    PHP代码优化技巧大盘点
    盘点PHP编程常见失误
    PHP Socket 编程详解
  • 原文地址:https://www.cnblogs.com/slgkaifa/p/6758648.html
Copyright © 2011-2022 走看看