Android中字体的处理 .

1、Android系统默认支持三种Android字体,分别为:"sans", "serif", "monospace"
2、在Android中可以引入其他字体

main.xml

  1. <spanstyle="font-size:16px;font-weight:normal;"><TableLayoutxmlns:android="http://schemas.android.com/apk/res/android"
  2. android:layout_height="fill_parent"
  3. android:layout_width="fill_parent"
  4. >
  5. <TableRow>
  6. <TextView
  7. android:layout_marginright="4px"
  8. android:text="sans:"
  9. android:textsize="20sp"
  10. />
  11. <!--使用默认的sans字体-->
  12. <TextView
  13. android:id="@+id/sans"
  14. android:text="Hello,World"
  15. android:textsize="20sp"
  16. android:typeface="sans"
  17. />
  18. </TableRow>
  19. <TableRow>
  20. <TextView
  21. android:layout_marginright="4px"
  22. android:text="serif:"
  23. android:textsize="20sp"
  24. />
  25. <!--使用默认的serifs字体-->
  26. <TextView
  27. android:id="@+id/serif"
  28. android:text="Hello,World"
  29. android:textsize="20sp"
  30. android:typeface="serif"
  31. />
  32. </TableRow>
  33. <TableRow>
  34. <TextView
  35. android:layout_marginright="4px"
  36. android:text="monospace:"
  37. android:textsize="20sp"
  38. />
  39. <!--使用默认的monospace字体-->
  40. <TextView
  41. android:id="@+id/monospace"
  42. android:text="Hello,World"
  43. android:textsize="20sp"
  44. android:typeface="monospace"
  45. />
  46. </TableRow>
  47. <!--这里没有设定字体,我们将在Java代码中设定-->
  48. <TableRow>
  49. <TextView
  50. android:layout_marginright="4px"
  51. android:text="custom:"
  52. android:textsize="20sp"
  53. />
  54. <TextView
  55. android:id="@+id/custom"
  56. android:text="Hello,World"
  57. android:textsize="20sp"
  58. />
  59. </TableRow>
  60. </TableLayout>
  61. </span>

FontsActivity.java

  1. <spanstyle="font-size:16px;font-weight:normal;">packageyyl.fonts;
  2. importAndroid.app.Activity;
  3. importAndroid.graphics.Typeface;
  4. importAndroid.os.Bundle;
  5. importAndroid.widget.TextView;
  6. publicclassFontsActivityextendsActivity{
  7. /**当activity第一次被创建的时候调用.*/
  8. @Override
  9. publicvoidonCreate(BundlesavedInstanceState){
  10. super.onCreate(savedInstanceState);
  11. setContentView(R.layout.main);
  12. //得到TextView控件对象
  13. TextViewtextView=(TextView)findViewById(R.id.custom);
  14. //将字体文件保存在assets/fonts/目录下,www.android-study.com创建Typeface对象
  15. TypefacetypeFace=Typeface.createFromAsset(getAssets(),"fonts/HandmadeTypewriter.ttf");
  16. //应用字体
  17. textView.setTypeface(typeFace);
  18. }
  19. }</span>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值