Android 字体相关总结
1、Android系统默认支持三种字体,分别为:“sans”, “serif”, “monospace“ 系统缺省方式(经试验缺省采用采用sans);
2、在Android中可以引入其他字体
3、示例如下:
4、布局文件
main.xml
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TableRow>
<TextView android:text="sans:"
android:layout_marginRight="4px"
android:textSize="20sp"></TextView>
<!-- 使用默认的sans字体-->
<TextView android:id="@+id/sans"
android:text="Hello,World"
android:typeface="sans"
android:textSize="20sp"></TextView>
</TableRow>
<TableRow>
<TextView android:text="serif:"
android:layout_marginRight="4px"
android:textSize="20sp"></TextView>
<!-- 使用默认的serifs字体-->
<TextView android:id="@+id/serif"
android:text="Hello,World"
android:typeface="serif"
android:textSize="20sp"></TextView>
</TableRow>
<TableRow>
<TextView android:text="monospace:"
android:layout_marginRight="4px"
android:textSize="20sp"></TextView>
<!-- 使用默认的monospace字体-->
<TextView android:id="@+id/monospace"
android:text="Hello,World"
android:typeface="monospace"
android:textSize="20sp"></TextView>
</TableRow>
<!-- 这里没有设定字体,我们将在Java代码中设定-->
<TableRow>
<TextView android:text="custom:"
android:layout_marginRight="4px"
android:textSize="20sp"></TextView>
<TextView android:id="@+id/custom"
android:text="Hello,World"
android:textSize="20sp"></TextView>
</TableRow>
</TableLayout>
5、Java代码
package yyl.fonts;
import android.app.Activity;
import android.graphics.Typeface;
import android.os.Bundle;
import android.widget.TextView;
public class FontsActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//得到TextView控件对象
TextView textView = (TextView)findViewById(R.id.custom);
//将字体文件保存在assets/fonts/目录下,创建Typeface对象
Typeface typeFace = Typeface.createFromAsset(getAssets(), "fonts/HandmadeTypewriter.ttf");
//应用字体
textView.setTypeface(typeFace);
}
}
android TextView设置中文字体加粗实现方法
英文设置加粗可以在xml里面设置:
英文还可以直接在String文件里面直接这样填写:
b代码加粗,i代表倾斜
中文设置加粗就需要在代码中获取到当前TextView在进行设置:
TextPaint tp = tv.getPaint();
tp.setFakeBoldText(true);
Android 字体相关总结的更多相关文章
- Android 字体修改,所有的细节都在这里 | 开篇
版权声明: 本账号发布文章均来自公众号,承香墨影(cxmyDev),版权归承香墨影所有. 每周会统一更新到这里,如果喜欢,可关注公众号获取最新文章. 未经允许,不得转载. 序 在 Android 下使 ...
- Android UI相关开源项目库汇总
最近做了一个Android UI相关开源项目库汇总,里面集合了OpenDigg 上的优质的Android开源项目库,方便移动开发人员便捷的找到自己需要的项目工具等,感兴趣的可以到GitHub上给个st ...
- Android界面相关的类
Android界面相关的类 Window Activity的显示界面对象,并作为顶层View被加入到WindowManager中.Window提供了标准的UI显示策略:界面背景.标题区域.默认的事件处 ...
- 一文让你彻底了解iOS字体相关知识
写本文的契机主要是把自己整理的关于iOS字体方面的知识不断更新写在这篇博文中,用来自己以后查阅. 一.iOS原生字体展示 在label中选择字体的font,并把font由system改成custom后 ...
- 如何让Android字体自适应屏幕分辨率
在不同的分辨率下,Android字体大小怎么自适应分辨率的变化? 假设需要适应320x240,480x320分辨率.在res目录下新建文件夹values-320x240, values-480x320 ...
- android 技术相关Blog
android 技术相关 LVXIANGAN的专栏 http://blog.csdn.net/LVXIANGAN/article/category/1101038 Android NFC 开发实例 h ...
- Android Studio相关的坑
html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,bi ...
- CSS3基础(2)—— 文字与字体相关样式、盒子类型、背景与边框相关样式、变形处理、动画功能
一. CSS3 文字与字体相关样式 1. 给文字添加阴影 text-shadow: length length length ccolor; 属性适用于文本阴影,指定了水平阴影,垂直阴影,模糊的距离, ...
- Android View相关知识问答
Android View相关核心知识问答 Activity Window View之间的三角关系 你真的了解View的坐标吗? 在渲染前获取 View 的宽高 5种手势工具类 浅析Android的窗口
随机推荐
- 20 个值得一试的JavaScript 框架
投递人 itwriter 发布于 2011-09-26 17:46 评论(3) 有1956人阅读 原文链接 [收藏] « » 本文介绍 20 个值得一试的 JavaScript 框架,如果你认为答 ...
- aws在线技术峰会笔记-主会场
容器服务:Elastic container service IoT可以采用无服务器架构.
- ubunt tmux X Error of failed request
X Error of failed request: BadName (named color or font does not exist) Major opcode of failed req ...
- PLS-00221: 'function' 不是过程或尚未定义
直接调用addOrgunitInfoByBatch(r_user_batch.seq_id,'01'); 报错PLS-00221: 'function' 不是过程或尚未定义 原因是在调用函数时 ...
- RMAN的入门篇
一.RMAN连接数据库 1. 连接本地数据库 [oracle@oracle hotbak]$ export oracle_sid=orcl [oracle@oracle hotbak]$ rman ...
- angular directive scope
angular directive scope 1.当directive 中不指定scope属性,则该directive 直接使用 app 的scope: 2.当directive 中指定scope属 ...
- 监控 Linux Unix Solaris AIX, swap page in / swap page out
vmstat 的 pi/po si/so --监控一天 vmstat 5 17280> vmstat.txt sar -W 1.得到数据 (linux 的 /var/log/sar/saX 自带 ...
- Evolutionary Computing: 3. Genetic Algorithm(2)
承接上一章,接着写Genetic Algorithm. 本章主要写排列表达(permutation representations) 开始先引一个具体的例子来进行表述 Outline 问题描述 排列表 ...
- EditText设置文字改变时的监听
textWatcher = new TextChangeWatcher(); etQuerryInfo.addTextChangedListener(textWatcher); /** * 文字改变类 ...
- IE11里边form拦截失效,永远被弹回登录页
现象描述: 1.在某些服务器上发布了程序以后,用IE11去浏览程序(试了多台电脑都一样),发现总是登录不进去,因为登录之后总是被立即反弹回登录页面,就像是登录后写入的票据瞬间丢失一样. 2.但是同一套 ...