前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >ttf设置文字字体

ttf设置文字字体

作者头像
xiangzhihong
发布2018-01-29 17:23:52
1.6K0
发布2018-01-29 17:23:52
举报
文章被收录于专栏:向治洪向治洪

MainActivity如下:

代码语言:java
复制
package cn.testfont;  
 
import android.os.Bundle;  
import android.widget.TextView;  
import android.app.Activity;  
import android.graphics.Typeface;  
/** 
 * Demo描述: 
 * 利用TTF字体文件文字的显示效果 
 *  
 * 步骤如下: 
 * 1 在asset下建立fonts文件夹 
 * 2 将.ttf文件拖入fonts文件夹Typeface 
 * 3 在代码中为TextView设置 
 * 
 */ 
public class MainActivity extends Activity {  
 private TextView mTextView;  
 @Override 
 protected void onCreate(Bundle savedInstanceState) {  
 super.onCreate(savedInstanceState);  
        setContentView(R.layout.main);  
        init();  
    }  
 
 private void init(){  
        mTextView=(TextView) findViewById(R.id.textView);  
        Typeface typeface = Typeface.createFromAsset(getAssets(),"fonts/test.ttf");  
        mTextView.setTypeface(typeface);  
    }  
}  

main.xml如下:

代码语言:html
复制
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
 xmlns:tools="http://schemas.android.com/tools" 
 android:layout_width="match_parent" 
 android:layout_height="match_parent" 
 > 
 
 <TextView 
 android:id="@+id/textView" 
 android:layout_width="wrap_content" 
 android:layout_height="wrap_content" 
 android:text="9527" 
 android:textSize="22sp" 
 android:layout_centerInParent="true" 
 /> 
 
</RelativeLayout> 
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2014-06-16 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档