整个项目要使用第三方字体首先将字体文件放到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. 纯js常用的代码

    1.获取表单中某属性的值 var name = document.myform.myname.value; 2.表单提交时校验,相应js代码中需要返回true或者false <form name ...

  2. CS程序中XML编码Encode和解码Decode

    VB6的代码,原则上只要是Windows系统均可以使用此方法 Function XMLEncode(ByVal text As String) As String Dim xmldoc Set xml ...

  3. python基础(六)——mysql的使用

    //验证是否安装mysqldb,这个是用于python连接mysql数据库的接口,而不是我们平时用的mysql import MySQLdb 安装MySQLdb,请访问 http://sourcefo ...

  4. Unity3D协同函数与异步加载功能实战 学习

  5. oracle-网络

    e10835 net reference /u01/app/oracle/diag/tnslsnr/oracle1/listener/trace/listener.log TIMESTAMP * CO ...

  6. try catch 用法实例

  7. kubernetes 中,Pod、Deployment、ReplicaSet、Service 之间关系分析

    deploy控制RS,RS控制Pod,这一整套,向外提供稳定可靠的Service. 详见:https://blog.csdn.net/ucsheep/article/details/81781509

  8. ES6 中 Class 与 TypeScript 中 Class 的区别(待补充)

    ES6 中 Class 与 TypeScript 中 Class 的区别(待补充)

  9. swiper4 一个页面多个轮播

    <div class="swiper-container"> <div class="swiper-wrapper"> <div ...

  10. 编译小米mini openwrt

    编译小米mini openwrt 1.下载openwrt源码包:进入要下载保存的文件目录,输入 git clone git://git.openwrt.org/15.05/openwrt.git 2. ...