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

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

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

public class CustomTextView extends TextView { 

    public CustomTextView(Context context) {
super(context);
init(context);
} public CustomTextView(Context context, AttributeSet attrs) {
super(context, attrs);
init(context);
} public CustomTextView(Context context, AttributeSet attrs, int defSyle) {
super(context, attrs, defSyle);
init(context);
} /***
* 设置字体
*
* @return
*/
public void init(Context context) {
setTypeface(FontCustom.setFont(context)); }
}
public class FontCustom {

    static String fongUrl = "fonts/fzltxh_gbk.ttf";
static Typeface tf; /***
* 设置字体
*
* @return
*/
public static Typeface setFont(Context context) {
if(tf==null){
tf = Typeface.createFromAsset(context.getAssets(), fongUrl);
}
return tf;
}
}

使用方法

<CustomTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="我是自定义字体"
android:textColor="@color/login_font_hit"
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. hdu4990 Reading comprehension 矩阵快速幂

    Read the program below carefully then answer the question.#pragma comment(linker, "/STACK:10240 ...

  2. linux磁盘检测和修复

    显示磁盘和闪存的信息,以及分区信息 [root@bogon shell]# fdisk -l Disk /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 s ...

  3. 文件访问控制列表facl

    [root@bogon code]# getfacl a.c //获取文件a.c的文件访问控制列表 # file: a.c # owner: root # group: root user::rw- ...

  4. MySQL Innodb Engine -- 文件格式(innodb_file_format)

    ======================================================== 在InnoDB 1.0.x版本之前,InnoDB 存储引擎提供了 Compact 和 ...

  5. Running Elixir in Docker Containers

    转自:https://www.poeticoding.com/running-elixir-in-docker-containers/ One of the wonderful things abou ...

  6. ElasticeSearch(五)分布式索引架构

    关于分布式架构 首先将ES默认每个索引是5个分片,这样做得目的是两个一个索引的时候速度更快(将数据写到小分片的尾部比写入大分片尾部更加快):另外一个是当数据量达到一定程度之后,分片查询,在汇总(sca ...

  7. EntityFrameworkCore操作记录

    Install-Package Microsoft.VisualStudio.Web.CodeGeneration.Design -Version 2.0.3 Add-Migration Init U ...

  8. 基于STM32的红外遥控重点解析

    本文有两个内容:一.红外遥控协议的的讲解:二.解码程序解析(参考正点原子的代码) 红外的介绍.优点.缺点就不给大家说了,进入正题 一.红外遥控协议的的讲解 红外遥控的编码目前广泛使用的是:NEC Pr ...

  9. enc28J60 网页控制LED灯

    软件IDE:Arduino 1.6.3 1.库的安装: 从https://github.com/jcw/ethercard 下载源码包,解压,复制ethercard-master文件夹到Arduino ...

  10. Docker安装 和简单使用

    1.安装依赖 yum install -y yum-utils device-mapper-persistent-data lvm2 2.这一步设置即将安装的是稳定版仓库 yum-config-man ...