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默 ...
随机推荐
- 安装,配置,启动FTP,SSH,NFS服务
1.安装,配置,启动FTP服务 sudo apt-get install vsftpd 修改vsftpd的配置文件/etx/vsftpd/.config,将下面几行前面的“#”去掉 #local_en ...
- 线程---插队和礼让执行(join和yield)
插队: 礼让:
- mysql 常用函数-locate 和 instr 和 regexp
★1 -- 表级锁 情况SHOW STATUS LIKE 'table%';-- 行级锁 情况SHOW STATUS LIKE 'innodb_row_lock%'; -- 进程列表SHOW PROC ...
- LeetCode - Diameter of Binary Tree
Given a binary tree, you need to compute the length of the diameter of the tree. The diameter of a b ...
- gtk_init()
#include<stdio.h> #if 0int main(int argc, char *argv[]){ char ***p = &argv; //传参退化成二级指针,对二 ...
- 02基于python玩转人工智能最火框架之TensorFlow人工智能&深度学习介绍
人工智能之父麦卡锡给出的定义 构建智能机器,特别是智能计算机程序的科学和工程. 人工智能是一种让计算机程序能够"智能地"思考的方式 思考的模式类似于人类. 什么是智能? 智能的英语 ...
- cookie和session机制
一.cookie和session机制之间的差别和联系 1.cookie机制 Cookie意为"甜饼",是由W3C组织提出,最早由Netscape社区发展的一种机制. 眼下Cooki ...
- 关于margin padding
margin padding设置百分比是以父元素的宽度作参考. 定位的left,top等取百分比 则以参照定位元素的padding+width做参考 margin 四个同时设定 以margin-lef ...
- 24 正则表达式 re模块
一.正则表达式 1.字符组 ① [abc] 匹配a或b或c ② [a-z] 匹配a到z之间的所有字⺟ [0-9]匹配所有阿拉伯数字 2.元字符 3.量词 4.重要搭配 ① .*? ② .*?x ...
- Jenkins进阶-应用的远程部署(12)
越来越多的公司部署需要实现自动化模式,大家的首选的工具就是Jenkins,下来介绍下通过Publish Over SSH Plugin插件实现远程部署: 一.安装插件Publish Over SSH ...