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


  • 相关阅读:
    cookie和session的区别和用法
    JavaScript深浅拷贝
    前端知识
    typescript -- ts
    vue笔记精华部分
    宜人贷项目里-----正则匹配input输入月份规则
    PHP-Socket-阻塞与非阻塞,同步与异步概念的理解
    PHP socket客户端长连接
    PHP exec/system启动windows应用程序,执行.bat批处理,执行cmd命令
    查看局域网内所有ip
  • 原文地址:https://www.cnblogs.com/donghaifeng-2016/p/5395262.html
Copyright © 2011-2022 走看看