Android学习记录 之 字体

来源:互联网 发布:淘宝规格怎么填写 编辑:程序博客网 时间:2024/05/17 22:27

在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