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

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="">

(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. [转载]Linux下终端字体颜色设置方法

    原文地址:Linux下终端字体颜色设置方法作者:router 网上类似的文章有很多,但是都是转来转去的,没有经过测试,按照很多文章的方法会造成你设置之后的终端在换行和删除输入字符时终端显示会乱七八糟, ...

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

    CSS 文本字体颜色设置方法(CSS color) 一.认识CSS 颜色(CSS color) 这里要介绍的是网页设置颜色包含有哪些:网页颜色规定规范. 1.常用颜色地方包含:字体颜色.超链接颜色.网 ...

  3. CSS 中的字体兼容写法:用CSS为英文和中文字体分别设置不同的字体

    font-family的调用方法: font-family:Arial,'Times New Roman','Microsoft YaHei',SimHei; font:bold 12px/.75em ...

  4. Sass、Less编译器koala及koala不支持中文字体的解决方法

    一款很好用的Sass编译器,还可以编译Less.coffeescript等 去官网下载适合自己电脑的版本 http://koala-app.com/index-zh.html 打开后拖动或者打开项目目 ...

  5. centos系统安装中文字体几种方法

    我们知道centos是基于linux内核的这款系统默认是不带中文字体了,如果我们要使用中文字体就需要自行安装了,下面一起来看看吧.   前天有用户反应,生成的报到单中他的名字少了一个字.仔细检查了一下 ...

  6. CSS为英文和中文字体分别设置不同的字体

    font-family的调用方法: div { font-family:Arial,'Times New Roman','Microsoft YaHei',SimHei; font:bold 12px ...

  7. xe6 android控件透明度设置方法

    今天才知道xe6 android控件的透明度设置方法:只需设置控件中的Opacity参数,默认为1--不透明 panel1.Opacity:=0.60;

  8. zabbix4.2升级后中文字体乱码解决方法.

    字体文件目录: zabbix 4.2 /usr/share/zabbix/assets/fonts/ 4.0 /usr/share/zabbix/fonts/ php 脚本文件位置: /usr/sha ...

  9. python-docx 设置标题heading的中文字体类型+设置正文的中文字体类型

    依赖包: from docx import Document from docx.shared import Pt from docx.shared import Inches from docx.o ...

随机推荐

  1. Android 开源项目android-open-project解析之(二) GridView,ImageView,ProgressBar,TextView

    五.GridView StaggeredGridView 同意非对齐行的GridView,类似Pinterest的瀑布流.而且跟ListView一样自带View缓存,继承自ViewGroup 项目地址 ...

  2. UVa 170 - Clock Patience

    题目:Clock Patience游戏,将52张扑克牌,按时钟依次分成13组(中心一组),每组4张全都背面向上, 从中间组最上面一张牌開始.翻过来设为当前值,然后取当前值相应组中最上面的背过去的牌翻过 ...

  3. leetcode dfs Palindrome Partitioning

    Palindrome Partitioning Total Accepted: 21056 Total Submissions: 81036My Submissions Given a string  ...

  4. ContextMenu的使用具体解释

    二话不说,先上图: 能够非常easy看到这是一个类似于Dialog悬浮在活动上的控件,它是由被注冊的view长按所触发的. 当然啦,也有其它的实现方式,这里就先介绍一下系统的ContextMenu:( ...

  5. hdu 3074 求区间乘积

    线段树水题 #include<stdio.h> #include<string.h> #include<iostream> using namespace std; ...

  6. 《Java虚拟机原理图解》 1.2.3、Class文件里的常量池具体解释(下)

    NO9.类中引用到的field字段在常量池中是如何描写叙述的?(CONSTANT_Fieldref_info, CONSTANT_Name_Type_info) 一般而言.我们在定义类的过程中会定义一 ...

  7. MongodDB用GridFS方式存取文件

    在实现GridFS方式前我先讲讲它的原理,为什么可以存大文件.驱动首先会在当前数据库创建两个集合:"fs.files"和"fs.chunks"集合,前者记录了文 ...

  8. c#自己实现线程池功能(二)

    介绍 在上一篇c#自己实现线程池功能(一)中,我们基本实现了一个能够执行的程序.而不能真正的称作线程池.因为是上篇中的代码有个致命的bug那就是没有任务是并非等待,而是疯狂的进行while循环,并试图 ...

  9. DB-MySQL:MySQL 临时表

    ylbtech-DB-MySQL:MySQL 临时表 1.返回顶部 1. MySQL 临时表 MySQL 临时表在我们需要保存一些临时数据时是非常有用的.临时表只在当前连接可见,当关闭连接时,Mysq ...

  10. docker迁移步骤

    1. 创建快照:docker commit -p 30b8f18f20b4 container-backup (可以通过docker images 查看docker镜像) 2. 镜像保存在本地机器中: ...