您的位置:首页 > 移动开发 > Android开发

android TextView字体切换

2015-07-06 19:44 621 查看
布局文件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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: