布局文件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.youkuaiyun.com/detail/ooppcool/8874189