Android学习记录 之 字体

在android系统中,自带的只有三种字体---"sans","serif"和"monospace",你只要在xml文件中的

Xml代码 
  1. android:typeface  
属性使用它们: 
Xml代码 
  1. <TableLayout  
  2.     xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:layout_width="fill_parent"  
  4.     android:layout_height="fill_parent"  
  5.     android:stretchColumns="1">  
  6.     <TableRow>  
  7.         <TextView  
  8.             android:text="sans:"  
  9.             android:layout_marginRight="4px"  
  10.             android:textSize="20sp"  
  11.         />  
  12.         <TextView  
  13.             android:id="@+id/sans"  
  14.             android:text="Hello, world!"  
  15.             android:typeface="sans"  
  16.             android:textSize="20sp"  
  17.         />  
  18.     </TableRow>  
  19.     <TableRow>  
  20.         <TextView  
  21.             android:text="serif:"  
  22.             android:layout_marginRight="4px"  
  23.             android:textSize="20sp"  
  24.         />  
  25.         <TextView  
  26.             android:id="@+id/serif"  
  27.             android:text="Hello, world!"  
  28.             android:typeface="serif"  
  29.             android:textSize="20sp"  
  30.         />  
  31.     </TableRow>  
  32.     <TableRow>  
  33.         <TextView  
  34.             android:text="monospace:"  
  35.             android:layout_marginRight="4px"  
  36.             android:textSize="20sp"  
  37.         />  
  38.         <TextView  
  39.             android:id="@+id/monospace"  
  40.             android:text="Hello, world!"  
  41.             android:typeface="monospace"  
  42.             android:textSize="20sp"  
  43.         />  
  44.     </TableRow>  
  45.     <TableRow>  
  46.         <TextView  
  47.             android:text="Custom:"  
  48.             android:layout_marginRight="4px"  
  49.             android:textSize="20sp"  
  50.         />  
  51.         <TextView  
  52.             android:id="@+id/custom"  
  53.             android:text="Hello, world!"  
  54.             android:textSize="20sp"  
  55.         />  
  56.     </TableRow>  
  57. </TableLayout>  

    有时候,系统自带的字体并不能满足我们特殊的需求,这时候就需要引用其他的字体了,可以把下载的字体文件放在assets目录下.自定义字体文件不能使用xml代码读取而应该使用java代码: 
Java代码 
  1. public class Test extends Activity {  
  2.     @Override  
  3.     public void onCreate(Bundle icicle) {  
  4.         super.onCreate(icicle);  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值