Android 使用自定义字体
整个项目要使用第三方字体首先将字体文件放到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 使用自定义字体的更多相关文章
- 转--Android中自定义字体的实现方法
1.Android系统默认支持三种字体,分别为:“sans”, “serif”, “monospace 2.在Android中可以引入其他字体 . 复制代码 代码如下: <?xml versio ...
- Android实现自定义字体
介绍 最近在看开源项目的时候,发现里面涉及到了自定义字体,虽然自己目前还用不到,但是动手demo笔记记录一下还是有必要的,没准哪天需要到这个功能. 原理 1.其实实现起来非常简单,主要是用到了Type ...
- Android Studio 自定义字体显示英文音标
android:fontFamily="serif" 网上查了很多自定义字体的方式,或多或少都有些麻烦,最后还是尝试着认为内置字体不应该实现不了英文音标问题,就一个一个字体试了一下 ...
- Typeface-为自定义字体提供字体内存缓存
Android 上自定义字体的代码一般如下: TextView textview = (TextView) findViewById(R.id.your_referenced_textview); / ...
- Android SearchView 自定义SearchIcon和字体颜色大小
自定义SearchView的搜索图标和字体属性相对复杂一些,记下来. 一.自定义SearchIcon 1.API版本低于21:版本小于21时,要修改SearchIcon比较复杂,需要先获取到Searc ...
- Android怎么使用字体图标 自定义FontTextView字体图标控件-- 使用方法
首先我想说明一下字体图标的好处,最大的好处就是自适应了,而且是使用TextView 不用去切图,是矢量图 灵活调用 第一步我要说明一下一般字体图标的来源,我这里使用的是 --阿里巴巴矢量图标库 -网 ...
- Android 中使用自定义字体的方法
1.Android系统默认支持三种字体,分别为:“sans”, “serif”, “monospace 2.在Android中可以引入其他字体 . <?xml version="1.0 ...
- 【Android 界面效果42】如何自定义字体
项目里要统一用设计师的字体,android:typeface只支持系统三种字体.有什么比较好的做法? 你需要为整个应用替换自定义字体. 解决方案 1)Android默认方法 #1 你可以通过ID查找到 ...
- Android:更好的自定义字体方案
http://ryanhoo.github.io/blog/2014/05/05/android-better-way-to-apply-custom-font/ 情景 解决方案 1)Android默 ...
随机推荐
- LA3641 Leonardo's Notebook
题意 PDF 分析 给出一个26个大写字母的置换B,是否存在A^2 = B 每个置换可以看做若干个循环的乘积.我们可以把这些循环看成中UVa 10294的项链, 循环中的数就相当于项链中的珠子. A^ ...
- Java基础七(Eclipse工具)
今日内容介绍1.Eclipse开发工具2.超市库存管理系统 ###01Eclipse的下载安装 * A: Eclipse的下载安装 * a: 下载 * http://www.eclipse.org ...
- Writing and playing with custom Terraform Providers
转自:https://petersouter.xyz/writing-and-playing-with-custom-terraform-providers/ I’ve been digging de ...
- microcks 微服务mocks 工具&&运行时
microcks 是一个方便的微服务mock 工具,我们可以用来mock request.response,同时获取api 的服务契约,microcks 支持的部署模式也比较多,docker-comp ...
- 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 ...
- Python自建collections模块
本篇将学习python的另一个内建模块collections,更多内容请参考:Python学习指南 collections是Python内建的一个集合模块,提供了许多有用的集合类. namedtupl ...
- 我发起了一个 .Net 开源 数据库 项目 SqlNet
大家好 , 我发起了一个 .Net 开源 数据库 项目 SqlNet . 项目计划 是 用 C# 写一个 关系数据库 . 可以先参考我之前写的 2 篇文章 : 谈谈数据库原理 https://w ...
- How to implement a windbg plugin
How to implement a windbg plugin Define EXT_CLASS #include "lauxlib.h" class EXT_CLASS : p ...
- [转]logback常用配置简介
logback是一套日志框架,由log4j的优化版,由同一个作者开发,在速度和性能上都超过其他日志框架,再结合slf4j,已成为当前最流行的日志框架. Logback最常用就是在classpath定义 ...
- node-sass 安装失败的原因及解决办法
出处:https://segmentfault.com/a/1190000010984731 windows 上用 yarn add node-sass --dev 也可以安装上.