text——为android系统添加一种默认字体,类似“sans”,“serif”,“monospace”
来源:互联网 发布:健康风险评估软件 编辑:程序博客网 时间:2024/05/01 13:47
1)在frameworks/base/data/fonts目录下添加字体文件,例如Driod-kaishu.ttf;
2)在skia中增加楷书这一字体,需要修改的文件主要有skFontHost.cpp、skTypeface.cpp、Typeface.java等;
3)在java层添加楷书字体相关API,需要修改的文件主要有typeface.java和textview.java;
4)编译SDK
5)将新生成的sdk导入eclipse,在eclipse中即可通过setTypeface(Typeface.KAISHU)和android:typeface=(“kaishu”)两种方式设置自己添加的字体。
以增加楷书字体为例:
main.xml
<?xmlversion="1.0"encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:orientation="vertical"android:layout_width="fill_parent"android:layout_height="fill_parent"android:background="#f3243646"><TextViewandroid:id="@+id/TextView1"android:layout_width="fill_parent"android:layout_height="wrap_content"android:text="@string/normal"android:typeface="normal"android:textSize="25px"/><TextViewandroid:id="@+id/TextView2"android:layout_width="fill_parent"android:layout_height="wrap_content"android:text="@string/sans"android:typeface="sans"android:textSize="25px"/><TextViewandroid:id="@+id/TextView3"android:layout_width="fill_parent"android:layout_height="wrap_content"android:text="@string/serif"android:typeface="serif"android:textSize="25px"/><TextViewandroid:id="@+id/TextView4"android:layout_width="fill_parent"android:layout_height="wrap_content"android:text="@string/monospace"android:typeface="monospace"android:textSize="25px"/><TextViewandroid:id="@+id/TextView5"android:layout_width="fill_parent"android:layout_height="wrap_content"android:text="@string/kaishu"android:typeface="kaishu"android:textSize="25px"/></LinearLayout>
String.xml
<?xmlversion="1.0"encoding="utf-8"?><resources><stringname="normal">(normal)字体测试!!!TypefacesTest!!!</string><stringname="app_name">Typefaces4</string><stringname="kaishu">(kaishu)字体测试!!!TypefacesTest!!!</string><stringname="sans">(sans)字体测试!!!TypefacesTest!!!</string><stringname="serif">(serif)字体测试!!!TypefacesTest!!!</string><stringname="monospace">(monospace)字体测试!!!TypefacesTest!!!</string></resources>
Typefaces4.java
packagecom.cy.Typefaces4; importandroid.app.Activity;importandroid.os.Bundle;importandroid.widget.TextView; publicclassTypefaces4 extendsActivity{/**Called when the activity is first created. */@OverridepublicvoidonCreate(BundlesavedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.main);}}
结果图如下:
需要注意的是,在一个TextView里的所有字符只能设置成一种字体,比如说textview.settext(“字体测试!!!TypefacesTest!!!”)中的所有字符只能被设置成同一种字体,如果想将“字体测试!!!”设置为楷书,而“TypefacesTest!!!”设置为sans就必须将这两段字符用两个TextView显示,并对各自的字体分别进行设置。
main.xml
<?xmlversion="1.0"encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:orientation="horizontal"android:layout_width="fill_parent"android:layout_height="fill_parent"android:background="#ffffffff"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/kaishu"android:textSize="30px"android:textColor="#ff000000"android:typeface="kaishu"/><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/sans"android:textSize="30px"android:textColor="#ff000000"android:typeface="sans"/></LinearLayout>
效果图如下:
ttf字体
TTF(TrueTypeFont)是Apple公司和Microsoft公司共同推出的字体文件格式,随着windows的流行,已经变成最常用的一种字体文件表示方式。是字库中的一种,应用范围非常广。
桌面出版系统使用的字库有两种标准:postscript字库和truetype字库。android系统中使用的是truetype,这两种字体标准都是采用曲线方式描述字体轮廓,因此都可以输出很高质量的字形。常用的字库标准是truetype字库,truetype字体是windows操作系统使用的唯一字体标准。truetype字体的最大优点是可以很方便地把字体轮廓转换成曲线,可以对曲线进行填充,制成各种颜色和效果,它可以进一步变形,制作特殊效果字体,因此经常用来制作一些标题字或花样字。truetype字便宜,字款丰富。
ttf与ttc字体有什么区别?
TrueType字体通常包含在单个TrueType字体文件中, 其文件后缀为.TTF。OpenType字体是以类似于TrueType字体的格式编码的POSTSCRIPT字体。OPENTYPE字体使用.OTF文件后缀。OPENTYPE还允许把多个 OPENTYPE字体组合在一个文件中以利于数据共享。这些字体被称为TrueType字体集(TrueType collection),其文件后缀为.TTC。
- text——为android系统添加一种默认字体,类似“sans”,“serif”,“monospace”
- 关于 Serif Sans-Serif Monospace 字体
- Sans Serif Serif Monospace
- sans-serif,serif,monospace
- Sans Serif 和 Serif 字体
- 细说字体 Sans Serif 与 Serif
- 细说字体 Sans Serif 与 Serif
- Sans Serif 与 Serif 字体是什么意思?
- 网页常用字体Sans-serif Serif
- Sans Serif 与 Serif 字体是什么意思?
- Sans Serif 与 Serif 字体是什么意思?
- Serif和Sans-serif字体的区别
- Serif 和 Sans Serif 字体的区别
- Serif和Sans-serif字体的区别
- Serif 和 Sans-serif 字体的区别
- Serif和Sans-serif字体的区别
- Serif和Sans-serif字体的区别
- Serif和Sans-serif字体的区别
- 移动端开发者眼中的前端开发流程变迁与前后端分离
- Android之Adapter的封装与抽象(三)
- JavaWeb:报错信息The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path
- 一个特殊的日子(20160801-0001)
- Python 为什么不解决四舍五入(round)的“bug”
- text——为android系统添加一种默认字体,类似“sans”,“serif”,“monospace”
- C#中的MessageBox消息对话框
- gc overhead limit exceeded eclipse错误解决方案
- 有限元漫谈
- Win10上MySQL免安装版配置及1067error解决办法
- Error:(1, 1) 错误: 非法字符: \65279 Error:(1, 10) 错误: 需要class, interface或enum Error:(1, 1) 错误: 非法字符: \6527
- 如何建立与Olingo V4 OData服务
- C++中static应用详解
- C# 无边框窗体 移动 两种方法