整个项目要使用第三方字体首先将字体文件放到assets文件夹下

因为整个项目要用第三方字体这里我重写了 TextView Button EditText 三个控件

以TextView 为例代码如下  其它控件一样换下继承

  1. public class CustomTextView extends TextView {
  2.  
  3. public CustomTextView(Context context) {
  4. super(context);
  5. init(context);
  6. }
  7.  
  8. public CustomTextView(Context context, AttributeSet attrs) {
  9. super(context, attrs);
  10. init(context);
  11. }
  12.  
  13. public CustomTextView(Context context, AttributeSet attrs, int defSyle) {
  14. super(context, attrs, defSyle);
  15. init(context);
  16. }
  17.  
  18. /***
  19. * 设置字体
  20. *
  21. * @return
  22. */
  23. public void init(Context context) {
  24. setTypeface(FontCustom.setFont(context));
  25.  
  26. }
  27. }
  1. public class FontCustom {
  2.  
  3. static String fongUrl = "fonts/fzltxh_gbk.ttf";
  4. static Typeface tf;
  5.  
  6. /***
  7. * 设置字体
  8. *
  9. * @return
  10. */
  11. public static Typeface setFont(Context context) {
  12. if(tf==null){
  13. tf = Typeface.createFromAsset(context.getAssets(), fongUrl);
  14. }
  15. return tf;
  16. }
  17. }

使用方法

  1. <CustomTextView
  2. android:layout_width="match_parent"
  3. android:layout_height="wrap_content"
  4. android:text="我是自定义字体"
  5. android:textColor="@color/login_font_hit"
  6. android:textSize="14.0sp" />

这样就实现了项目字体统一风格

Android 使用自定义字体的更多相关文章

  1. 转--Android中自定义字体的实现方法

    1.Android系统默认支持三种字体,分别为:“sans”, “serif”, “monospace 2.在Android中可以引入其他字体 . 复制代码 代码如下: <?xml versio ...

  2. Android实现自定义字体

    介绍 最近在看开源项目的时候,发现里面涉及到了自定义字体,虽然自己目前还用不到,但是动手demo笔记记录一下还是有必要的,没准哪天需要到这个功能. 原理 1.其实实现起来非常简单,主要是用到了Type ...

  3. Android Studio 自定义字体显示英文音标

    android:fontFamily="serif" 网上查了很多自定义字体的方式,或多或少都有些麻烦,最后还是尝试着认为内置字体不应该实现不了英文音标问题,就一个一个字体试了一下 ...

  4. Typeface-为自定义字体提供字体内存缓存

    Android 上自定义字体的代码一般如下: TextView textview = (TextView) findViewById(R.id.your_referenced_textview); / ...

  5. Android SearchView 自定义SearchIcon和字体颜色大小

    自定义SearchView的搜索图标和字体属性相对复杂一些,记下来. 一.自定义SearchIcon 1.API版本低于21:版本小于21时,要修改SearchIcon比较复杂,需要先获取到Searc ...

  6. Android怎么使用字体图标 自定义FontTextView字体图标控件-- 使用方法

    首先我想说明一下字体图标的好处,最大的好处就是自适应了,而且是使用TextView 不用去切图,是矢量图 灵活调用 第一步我要说明一下一般字体图标的来源,我这里使用的是  --阿里巴巴矢量图标库 -网 ...

  7. Android 中使用自定义字体的方法

    1.Android系统默认支持三种字体,分别为:“sans”, “serif”, “monospace 2.在Android中可以引入其他字体 . <?xml version="1.0 ...

  8. 【Android 界面效果42】如何自定义字体

    项目里要统一用设计师的字体,android:typeface只支持系统三种字体.有什么比较好的做法? 你需要为整个应用替换自定义字体. 解决方案 1)Android默认方法 #1 你可以通过ID查找到 ...

  9. Android:更好的自定义字体方案

    http://ryanhoo.github.io/blog/2014/05/05/android-better-way-to-apply-custom-font/ 情景 解决方案 1)Android默 ...

随机推荐

  1. LA3641 Leonardo's Notebook

    题意 PDF 分析 给出一个26个大写字母的置换B,是否存在A^2 = B 每个置换可以看做若干个循环的乘积.我们可以把这些循环看成中UVa 10294的项链, 循环中的数就相当于项链中的珠子. A^ ...

  2. Java基础七(Eclipse工具)

    今日内容介绍1.Eclipse开发工具2.超市库存管理系统 ###01Eclipse的下载安装 * A: Eclipse的下载安装  * a: 下载 * http://www.eclipse.org ...

  3. Writing and playing with custom Terraform Providers

    转自:https://petersouter.xyz/writing-and-playing-with-custom-terraform-providers/ I’ve been digging de ...

  4. microcks 微服务mocks 工具&&运行时

    microcks 是一个方便的微服务mock 工具,我们可以用来mock request.response,同时获取api 的服务契约,microcks 支持的部署模式也比较多,docker-comp ...

  5. Coding kata: get the top two teams in one group

    In this week, we did a coding kata, the subject is to select the top two teams of football group mat ...

  6. Python自建collections模块

    本篇将学习python的另一个内建模块collections,更多内容请参考:Python学习指南 collections是Python内建的一个集合模块,提供了许多有用的集合类. namedtupl ...

  7. 我发起了一个 .Net 开源 数据库 项目 SqlNet

    大家好 , 我发起了一个 .Net 开源 数据库 项目 SqlNet . 项目计划 是 用 C# 写一个 关系数据库 . 可以先参考我之前写的 2 篇文章 : 谈谈数据库原理    https://w ...

  8. How to implement a windbg plugin

    How to implement a windbg plugin Define EXT_CLASS #include "lauxlib.h" class EXT_CLASS : p ...

  9. [转]logback常用配置简介

    logback是一套日志框架,由log4j的优化版,由同一个作者开发,在速度和性能上都超过其他日志框架,再结合slf4j,已成为当前最流行的日志框架. Logback最常用就是在classpath定义 ...

  10. node-sass 安装失败的原因及解决办法

    出处:https://segmentfault.com/a/1190000010984731 windows 上用 yarn add node-sass --dev 也可以安装上.