zoukankan      html  css  js  c++  java
  • 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.  字体包不小......             


  • 相关阅读:
    luogu P3128 [USACO15DEC]最大流Max Flow (树上差分)
    codeforces 600E . Lomsat gelral (线段树合并)
    bzoj 1483: [HNOI2009]梦幻布丁 (链表启发式合并)
    bzoj 1257: [CQOI2007]余数之和 (数学+分块)
    codevs 2606 约数和问题 (数学+分块)
    bzoj 2038: [2009国家集训队]小Z的袜子(hose) (莫队)
    bzoj 1086: [SCOI2005]王室联邦 (分块+dfs)
    bzoj 4542: [Hnoi2016]大数 (莫队)
    【NOIp模拟赛】Tourist Attractions
    【NOIp模拟赛】String Master
  • 原文地址:https://www.cnblogs.com/donghaifeng-2016/p/5395262.html
Copyright © 2011-2022 走看看