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的窗口
随机推荐
- dojox.grid.DataGrid
创建表格 <table data-dojo-type="dojox.grid.DataGrid" data-dojo-id="grid" style=&q ...
- ArcgisAdd-In开发入门实例
1.开发环境 Vs2012+Arcgis10.2+win7 64bit 2.实现代码 首先在VS2012中新建一个解决方案,命名AddInTest. 接着,给解决方案AddInTest新建一个项目: ...
- Ubuntu快捷键
https://linux.cn/article-3025-1.html 超级键操作 1.超级键(Win键)–打开dash. 2.长按超级键– 启动Launcher.并快捷键列表. 3.按住超级键,再 ...
- [bzoj1103][POI2007]大都市meg(树状数组+dfs序)
1103: [POI2007]大都市meg Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 2031 Solved: 1069[Submit][Sta ...
- jquery mobile的事件
有个问题困扰了我两天,知道今天才解决. 那就是page的pagecreate事件,只调用一次 如果想随时更新,就要调用pageshow事件,每次都会调用, 这个事情再次告诉我,基础要扎实啊,不然会浪费 ...
- 20160928_CentOS6.4x64_Oracle11gR2x64
1.“Oracle Database 11g Release 2” 下载地址: http://www.oracle.com/technetwork/database/enterprise-editio ...
- iOS中JS 与OC的交互(JavaScriptCore.framework)
iOS中实现js与oc的交互,目前网上也有不少流行的开源解决方案: 如:react native 当然一些轻量级的任务使用系统提供的UIWebView 以及JavaScriptCore.framewo ...
- Security » Authorization » 基于自定义策略的授权
Custom Policy-Based Authorization¶ 基于自定义策略的授权 98 of 108 people found this helpful Underneath the cov ...
- 使用XML文件和Java代码控制UI界面
Android推荐使用XML文件设置UI界面,然后用Java代码控制逻辑部分,这体现了MVC思想. MVC全名是Model View Controller,是模型(model)-视图(view)-控制 ...
- Monkey环境配置
安卓APP想要测试稳定性,monkey是最佳选则. 首先搭建monkey的运行环境 在Windows下基于SDK 1.下载SDK for Windows 解压:android-sdk-windows ...