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


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

    2.  studio中srcmain创建assetsfonts,存放字体包

    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.  字体包不小......             


  • 相关阅读:
    Spark实战练习03--Pair RDD
    Spark实战练习02--处理分隔符
    Spark实战练习01--XML数据处理
    做一个”合格“的程序员(二)——学习管理
    做一个“合格”的程序员(一)——基础能力
    图像处理算法之帧间差分法
    图像几何变换之透视变换
    图像几何变换之仿射变换
    内部排序之简单选择排序
    非极大值抑制算法
  • 原文地址:https://www.cnblogs.com/donghaifeng-2016/p/5395262.html
Copyright © 2020-2023  润新知