android TextView字体切换

来源:互联网 发布:think php框架 编辑:程序博客网 时间:2024/05/22 15:11

布局文件activity_main.xml 内容:

<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/mHelloWordTv"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="@string/hello_world" /></RelativeLayout>

MaintActivity

public class MainActivity extends Activity {    /** 资源文件路径 */    public static final String FONTS_PATH = "fonts/GBK.TTF";    /**要改变字体的TextView*/    private TextView mHelloWordTv;    /**字体*/    private Typeface mTf;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        initViews();    }    private void initViews() {        mHelloWordTv = (TextView)findViewById(R.id.mHelloWordTv);        mTf = Typeface.createFromAsset(getAssets(),FONTS_PATH);        mHelloWordTv.setTypeface(mTf);    }}

资源文件放置位置
这里写图片描述

运行,测试搞定.
源代码:http://download.csdn.net/detail/ooppcool/8874189

0 0
原创粉丝点击