Android TextView字体颜色等样式具体解释连接:http://blog.csdn.net/pcaxb/article/details/47341249

1.使用字体库(自己定义字体的使用):当然假设字体库和手机的不兼容获取什么的,可能你的中文是无效的

(1)在assets中新建文件夹fonts,把ttf字体库考到文件夹下

(2)使用代码

TextView view1 = (TextView) findViewById(R.id.tv1);
Typeface tf1 = Typeface.createFromAsset(getAssets(), "fonts/DroidSerif-Bold.ttf");

view1.setTypeface(tf1);

(3)使用字体库的问题和解决

问题:假设你的字体库太大(xM),就会抛java.lang.RuntimeException: native typeface cannot be made

异常。当然抛这个异常不一定是字体库大了。

解决:

用到的软件
(a)FontCreator字库浏览软件
(b)FontSubset大字库化小字库软件
工具下载地址:http://download.csdn.net/detail/pcaxb/8972239

操作使用

(a)打开FontSubset,执行FontSubsetGUI.exe
(b)填上数据
source font 是你的当前要切割的字体包
new font 是你要切割后的字体
char list 能够选你当前切割的字体包
encodeing 选utf-8

点击 process

字体库的下载链接(这里的字体库是我用FontSubset压缩了的,很小):http://download.csdn.net/detail/pcaxb/8974239

(4)Android字体系统库(了解)

Android System Fonts(/system/fonts):
AndroidClock.ttf
AndroidClock_Highlight.ttf
AndroidClock_Solid.ttf
AndroidEmoji.ttf
Clockopia.ttf
DroidNaskh-Regular.ttf
DroidNaskhUI-Regular.ttf
DroidSans-Bold.ttf
DroidSans.ttf
DroidSansArmenian.ttf
DroidSansEthiopic-Regular.ttf
DroidSansFallback.ttf
DroidSansGeorgian.ttf
DroidSansHebrew-Bold.ttf
DroidSansHebrew-Regular.ttf
DroidSansMono.ttf
DroidSerif-Bold.ttf
DroidSerif-BoldItalic.ttf
DroidSerif-Italic.ttf
DroidSerif-Regular.ttf
MTLmr3m.ttf
Roboto-Bold.ttf
Roboto-BoldItalic.ttf
Roboto-Italic.ttf
Roboto-Light.ttf
Roboto-LightItalic.ttf
Roboto-Regular.ttf
Roboto-Thin.ttf
Roboto-ThinItalic.ttf
RobotoCondensed-Bold.ttf
RobotoCondensed-BoldItalic.ttf
RobotoCondensed-Italic.ttf
RobotoCondensed-Regular.ttf

2.设置字体的相关属性

(1)android:fontFamily的使用方法(有较高版本号的限制)

相关属性:sans-serif、sans-serif-light、sans-serif-condensed、sans-serif-thin、

(2)android:textStyle="normal|bold|italic"

相关属性Regular、Italic、、Bold、Bold-italic、Light、Light-italic、Thin、Thin-italic、Condensed regular、Condensed italic、Condensed bold、Condensed bold-italic
android:textStyle="bold"能够将英文设置成粗体, 可是不能将中文设置成粗体。

代码设置

TextView tv = (TextView)findViewById(R.id.TextView01);
tv.getPaint().setFakeBoldText(true);//使用TextPaint的仿粗体设置setFakeBoldText为true

(3)android:fontFamily与 android:typeface

相关属性:normal、sans、serif、monospace
參考链接:
http://developer.android.com/reference/android/widget/TextView.html#attr_android%3atypeface
http://stackoverflow.com/questions/12128331/how-to-change-fontfamily-of-textview-in-android

3.通过HTML标签设置字体(注意有些标签是没有效果的):

Button btn = (Button) findViewById(R.id.bt);
String source =  "这仅仅是一个測试字符串,測试<b>黑体字</b>、<i>斜体字</i>、<u>下划线</u>、<font color='red' face='微软雅黑'>红色字</font>的显示。<font face='幼圆' size='1' color='green'>幼圆一号绿色字体</font>" +"<font face='宋体'>字体</font>" +"<font face='微软雅黑'>字体</font>" +"<font face='宋体'>nishiwode</font>" +"<font face='微软雅黑'>nishiwode</font>";
btn.setText(Html.fromHtml(source));
btn.setOnFocusChangeListener(this);

4.通过以下这样的方式的没有什么效果

Typeface tf1 = Typeface.create("宋体", Typeface.NORMAL);
Typeface tf1 = Typeface.create("sans-serif", Typeface.NORMAL);

Android 中文字体的设置方法和使用技巧相关推荐

  1. QT中文字体的显示方法

    QT中文字体的显示方法 一.QT显示中文失败的原因,如显示为方块或乱码 1)qte的库未编译进对中文textcodec的支持,解决方案:修改qconfig-qpe.h, 去掉CODEC有关的宏,重新c ...

  2. Python-docx 模块读写 Word 文档基础(一):创建文档、段落格式、字体格式设置方法

    Python-docx 模块读写 Word 文档基础(一):创建文档.段落格式.字体格式设置方法 前言: 1.创建 Word 文档及基础用法: 2.段落格式设置: 3.字体格式设置: 结尾: [Pyt ...

  3. Foxmail邮件字体大小怎么设置 Foxmail字体的设置方法

    Foxmail写邮件的时候,想要设置邮件的字体,和字体大小,该怎么设置呢?下面我们就来看看详细的教程. Foxmail邮件字体大小怎么设置? Foxmail字体的设置方法 1.下载并安装Foxmail ...

  4. matplotlib 无法显示中文字体的解决方法

    matplotlib 无法显示中文字体的解决方法 参考文章: (1)matplotlib 无法显示中文字体的解决方法 (2)https://www.cnblogs.com/lingLongBaby/p ...

  5. CSS 文本字体颜色设置方法。

    这篇文章主要介绍了CSS 文本字体颜色设置方法(CSS color),需要的朋友可以参考下 一.认识CSS 颜色(CSS color) 这里要介绍的是网页设置颜色包含有哪些:网页颜色规定规范. 1.常 ...

  6. android 恢复出厂设置流程分析,基于Android系统快速恢复出厂设置方法实现.doc

    基于Android系统快速恢复出厂设置方法实现 基于Android系统快速恢复出厂设置方法实现 摘 要:针对使用Android系统的智能电视进行恢复出厂设置时重置速度慢的情况进行了研究和分析,从其重置 ...

  7. html火狐定义字体大小,火狐浏览器字体大小设置方法

    火狐浏览器字体大小设置方法,火狐浏览器字体太小的话,看小说.看八卦.看杂志.看军事新闻.看今日头条都很不方便,对眼睛也不好,怎么让Firefox浏览器字体设置大一些呢?下面小编就为大家分享一下吧. 火 ...

  8. CSS 文本字体颜色设置方法(CSS color)

    转自:微点阅读  https://www.weidianyuedu.com 这篇文章主要介绍了CSS 文本字体颜色设置方法(CSS color),需要的朋友可以参考下 一.认识CSS 颜色(CSS c ...

  9. Matplotlib画图中文字体乱码设置

    Matplotlib画图中文字体乱码设置 Matplotlib画图中文字体乱码设置 一.字体基本设置 二.其他字体: 三.展示一下: 四.运行结果: Matplotlib画图中文字体乱码设置 一.字体 ...

最新文章

  1. Python Module_subprocess_调用 Powershell
  2. ProxySQL 故障
  3. 智能门锁芯片V12_智能门锁方案应用开发的组成结构
  4. Waveform Audio 驱动(Wavedev2)之:WAV 驱动解析
  5. VBoxManage: error: Nonexistent host networking interface, name 'vboxnet0' (VERR_INTERNAL_ERROR)
  6. 开启Python之路
  7. Spring源码分析之BeanPostProcessor接口和BeanFactoryPostProcessor接口方法不执行原因分析
  8. jenkins的groovy脚本没权限
  9. 设某一机器由n个部件组成_组成原理
  10. 【TWVRP】基于matlab A_star算法求解带时间窗和任务软时间窗多车场多车型车辆路径问题【含Matlab源码 1561期】
  11. 检索 COM 类工厂中 CLSID 为 {000209FF-0000-0000-C000-000000000046} 的组件失败,原因是出现以下错误: 8000401a 因为配置标识不正确
  12. 业务数据双中台助力实现大型医药集团
  13. Macbook PS快捷键
  14. 大数据的核心价值是什么?
  15. Python入门-网络编程
  16. java中graphics_在java中如何绘图?Graphics类是什么意思?
  17. 如何消除Permission is only granted to system apps报错
  18. HTML页面刷新方法
  19. python读取.data文件总结
  20. python画圣诞树

热门文章

  1. [录1953-1-13] 郭沫若, 宋庆龄 Сталина 谈话记录
  2. iOS 基础 第五天(0811)
  3. IOS view的圆角和阴影并存
  4. 理解perl的编码转换——utf8以及乱码
  5. [转]如何使用BackTrack破解WIFI无线网络的WEP密钥
  6. ural 1012K-based Numbers. Version 2 1013. K-based Numbers. Version 3
  7. 江苏实时分析评价系统项目总结报告
  8. [转]Time Tracker Starter Kit 简介
  9. pytorch---之torch.manual_seed()
  10. 【学习OpenCV4】什么是图像的直方图?如何获取直方图?