textview设置字体以及引入新字体

来源:互联网 发布:淘宝女装批发网 编辑:程序博客网 时间:2024/05/01 21:37

首先介绍三种默认字体的设置

<!--  使用默认的sans字体-->

        <TextView    Android:id="@+id/sans"
                   Android:text="Hello,World"
                   Android:typeface="sans"
                   Android:textSize="20sp" />

<!--  使用默认的serifs字体-->
        <TextView   Android:id="@+id/serif"
                   Android:text="Hello,World"
                   Android:typeface="serif"
                   Android:textSize="20sp" />

<!--  使用默认的monospace字体-->
        <TextView   Android:id="@+id/monospace"
                   Android:text="Hello,World"
                   Android:typeface="monospace"
                   Android:textSize="20sp" /》


接下来介绍如何引入新字体




建立assets文件在创建fonnts文件夹

然后把**.ttf文件(字体文件)添加进去

最后调用代码


TextView textView =(TextView)findViewById(R.id.text);        //将字体文件保存在assets/fonts/目录下,创建Typeface对象        Typeface typeface = Typeface.createFromAsset(getAssets(), "fonnts/fangsong.ttf");//使用字体成仿宋体        textView.setTypeface(typeface);
这里有个仿宋字体供大家尝试

0 0
原创粉丝点击