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

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

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

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

方法二:



相关文章:

  • 2021-10-21
  • 2021-04-08
  • 2021-06-14
  • 2022-01-27
  • 2021-11-28
  • 2021-08-29
  • 2021-06-15
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-09-26
  • 2021-06-26
  • 2022-12-23
  • 2021-10-20
  • 2021-07-18
相关资源
相似解决方案