TextView自定义字体
16lz
2021-01-23
1. 定义包含1 TextView 布局:main.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:id="@+id/text" android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="center" /> </LinearLayout>
2. 下载字体文件 后缀名一般为:*.ttf 如:本例为:biscuit_tin.ttf
* 在工程目录下的 assets 目录下新建文件夹:fonts 然后把*.ttf文件 复制至该目录 并刷新工程
* 代码
public class MyTextTest extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Typeface fontFace = Typeface.createFromAsset(getAssets(), "fonts/biscuit_tin.ttf"); TextView text = (TextView)findViewById(R.id.text); text.setTypeface(fontFace); text.setText("Hello World!"); text.setTextSize(100); } }
更多相关文章
- 《android的SQLite与文件下载》
- Android Studio 与git 添加忽略文件
- android 入门学习笔记 上传大文件
- android实现文件读写功能
- Android 本地文件上传到服务器
- android--------根据文件路径加载指定文件
- android用于打开各种文件的intent,包括以下文件PDF,PPT,WORD,EXC
- android 删除sdcard中文件命令
- android 不能安装超过600MB文件?