`
zhujianjia
  • 浏览: 478488 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

TextView自定义字体

阅读更多

1. 定义包含1 TextView 布局:main.xml

 

<?xml version="1.0" encoding="utf-8"?>  
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
    android:orientation="vertical"  
    android:layout_width="fill_parent"  
    android:layout_height="fill_parent"  
    >  
<TextView    
    android:id="@+id/text"  
    android:layout_width="fill_parent"   
    android:layout_height="fill_parent"   
    android:gravity="center"  
    />  
</LinearLayout> 

 

 

 

2. 下载字体文件 后缀名一般为:*.ttf 如:本例为:biscuit_tin.ttf

 

* 在工程目录下的 assets 目录下新建文件夹:fonts 然后把*.ttf文件 复制至该目录 并刷新工程

 

* 代码

public class MyTextTest extends Activity {  
    /** Called when the activity is first created. */  
    @Override  
    public void onCreate(Bundle savedInstanceState) {  
        super.onCreate(savedInstanceState);  
        setContentView(R.layout.main);  
          
        Typeface fontFace = Typeface.createFromAsset(getAssets(), "fonts/biscuit_tin.ttf");  
          
        TextView text = (TextView)findViewById(R.id.text);  
        text.setTypeface(fontFace);  
        text.setText("Hello World!");  
        text.setTextSize(100);  
    }  
}  
 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics