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里面设置:

代码如下:
<SPAN style="FONT-SIZE: 18px">android:textStyle="bold"</SPAN> 

英文还可以直接在String文件里面直接这样填写:

代码如下:
<string name="styled_text">Plain, <b>bold</b>, <i>italic</i>, <b><i>bold-italic</i></b></string> 

b代码加粗,i代表倾斜 
中文设置加粗就需要在代码中获取到当前TextView在进行设置:

代码如下:
TextView tv = (TextView)findViewById(R.id.tv); 
TextPaint tp = tv.getPaint(); 
tp.setFakeBoldText(true); 

Android 字体相关总结的更多相关文章

  1. Android 字体修改,所有的细节都在这里 | 开篇

    版权声明: 本账号发布文章均来自公众号,承香墨影(cxmyDev),版权归承香墨影所有. 每周会统一更新到这里,如果喜欢,可关注公众号获取最新文章. 未经允许,不得转载. 序 在 Android 下使 ...

  2. Android UI相关开源项目库汇总

    最近做了一个Android UI相关开源项目库汇总,里面集合了OpenDigg 上的优质的Android开源项目库,方便移动开发人员便捷的找到自己需要的项目工具等,感兴趣的可以到GitHub上给个st ...

  3. Android界面相关的类

    Android界面相关的类 Window Activity的显示界面对象,并作为顶层View被加入到WindowManager中.Window提供了标准的UI显示策略:界面背景.标题区域.默认的事件处 ...

  4. 一文让你彻底了解iOS字体相关知识

    写本文的契机主要是把自己整理的关于iOS字体方面的知识不断更新写在这篇博文中,用来自己以后查阅. 一.iOS原生字体展示 在label中选择字体的font,并把font由system改成custom后 ...

  5. 如何让Android字体自适应屏幕分辨率

    在不同的分辨率下,Android字体大小怎么自适应分辨率的变化? 假设需要适应320x240,480x320分辨率.在res目录下新建文件夹values-320x240, values-480x320 ...

  6. android 技术相关Blog

    android 技术相关 LVXIANGAN的专栏 http://blog.csdn.net/LVXIANGAN/article/category/1101038 Android NFC 开发实例 h ...

  7. Android Studio相关的坑

    html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,bi ...

  8. CSS3基础(2)—— 文字与字体相关样式、盒子类型、背景与边框相关样式、变形处理、动画功能

    一. CSS3 文字与字体相关样式 1. 给文字添加阴影 text-shadow: length length length ccolor; 属性适用于文本阴影,指定了水平阴影,垂直阴影,模糊的距离, ...

  9. Android View相关知识问答

    Android View相关核心知识问答 Activity Window View之间的三角关系 你真的了解View的坐标吗? 在渲染前获取 View 的宽高 5种手势工具类 浅析Android的窗口

随机推荐

  1. JAVA-Semaphore信号灯-可实现维护自身线程访问数

    import java.util.Random; import java.util.concurrent.ExecutorService; import java.util.concurrent.Ex ...

  2. Bootstrap_导航

    一.标签形tab导航 标签形导航,也称为选项卡导航. 标签形导航是通过“.nav-tabs”样式来实现.在制作标签形导航时需要在原导航“.nav”上追加此类名. <ul class=" ...

  3. 计算城市间的球面距离(C++实现)

    #include<iostream> #include<string> #include<cmath> #include<iomanip> using ...

  4. GridControl

    隐藏Drag a column header here to group by that column https://www.devexpress.com/Support/Center/Questi ...

  5. Sqrt(x) - LintCode

    examination questions Implement int sqrt(int x). Compute and return the square root of x. Example sq ...

  6. 系统收到了多个不同的 Content-Disposition 标头。为了避免遭到 HTTP 响应拆分攻击,这种情况是不允许的。

    今天使用Struts2进行上传下载的时候发现了一个现象 我的Struts2配置文件 <action name="share_ExportExcel" class=" ...

  7. SAP的物料归档

    我们在对前台对物料进行删除时,是物理删除,也就是打个删除标志,并没有正真的从数据库里删除,在前台还是可以看到的,下面介绍一下SAP的归档处理可以 把已删除的物料在前台删除掉,注意:项目里根据情况得到领 ...

  8. Ubuntu 16.04.1下修改MySQL默认编码

    在Ubuntu 下配置 MySQL 的字符编码.安装完 MySQL 后,系统默认的字符编码是 latin1 ,输入的是中文,可是输出却是一堆乱码.现在要做的就是把 MySQL的默认字符编码设置为支持中 ...

  9. laravel开发微信公众号1 之基本配置

    需要用到的packagist:       https://github.com/overtrue/laravel-wechat  ( 目前最优雅的laravel微信sdk) 首先安装 compose ...

  10. 【python】selenium+python自动化测试环境搭建

    参考资料: http://www.cnblogs.com/fnng/archive/2013/05/29/3106515.html http://www.easonhan.info/python/20 ...