ttf设置文字字体

简介: MainActivity如下: [java] view plaincopy package cn.testfont;    import android.os.Bundle;  import android.widget.TextView;  import android.app.Activity;  import android.graphics.Ty

MainActivity如下:

  1. package cn.testfont;  
  2.   
  3. import android.os.Bundle;  
  4. import android.widget.TextView;  
  5. import android.app.Activity;  
  6. import android.graphics.Typeface;  
  7. /** 
  8.  * Demo描述: 
  9.  * 利用TTF字体文件文字的显示效果 
  10.  *  
  11.  * 步骤如下: 
  12.  * 1 在asset下建立fonts文件夹 
  13.  * 2 将.ttf文件拖入fonts文件夹Typeface 
  14.  * 3 在代码中为TextView设置 
  15.  * 
  16.  */  
  17. public class MainActivity extends Activity {  
  18.     private TextView mTextView;  
  19.     @Override  
  20.     protected void onCreate(Bundle savedInstanceState) {  
  21.         super.onCreate(savedInstanceState);  
  22.         setContentView(R.layout.main);  
  23.         init();  
  24.     }  
  25.   
  26.     private void init(){  
  27.         mTextView=(TextView) findViewById(R.id.textView);  
  28.         Typeface typeface = Typeface.createFromAsset(getAssets(),"fonts/test.ttf");  
  29.         mTextView.setTypeface(typeface);  
  30.     }  
  31. }  

main.xml如下:
  1. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  2.     xmlns:tools="http://schemas.android.com/tools"  
  3.     android:layout_width="match_parent"  
  4.     android:layout_height="match_parent"  
  5.     >  
  6.   
  7.     <TextView  
  8.         android:id="@+id/textView"  
  9.         android:layout_width="wrap_content"  
  10.         android:layout_height="wrap_content"  
  11.         android:text="9527"  
  12.         android:textSize="22sp"  
  13.         android:layout_centerInParent="true"  
  14.      />  
  15.   
  16. </RelativeLayout> 
目录
相关文章
LaTeX:字体字号榜值对比
LaTeX 的字体大小设置有 `\small, \large` 等,与 Word 上的字号大小有对应
360 0
|
前端开发 开发者
字体 | 学习笔记
快速学习字体
115 0
字体 | 学习笔记
html+css实战52-文字-字体
html+css实战52-文字-字体
102 0
html+css实战52-文字-字体
|
XML 数据格式
关于字体编码的一些知识,并带大家制作一套字体。(上)
关于字体编码的一些知识,并带大家制作一套字体。
关于字体编码的一些知识,并带大家制作一套字体。(上)
|
图形学
字体问题
字体问题
129 0
|
Python
在Maptlotlib中使用Helvetica字体
关注九天学者微信公众号(扫码关注)第一时间获取技术贴更新! 在学术论文中的图件(Scientific figures),优秀的图有四个特点:简单(Simple)、清晰(Clean)、易读(undisputedly easy to read)、美观。
1305 0