android点滴(29) android中设置用户自定义的字体
16lz
2021-01-23
android中要设定用户自己的字体很简单。
1.把自己的字体文件放入assets目录下
2.加载字体
3.给View设置字体
至于字体文件从哪里来就不多说了,可以自己制作也可以从论坛上下载。
第一步也很简单过。
直接上第二部加载字体,这里看一下android的Typeface(字体)类,下面的几个就是加载字体的静态方法。
1 public staticTypefacecreate(StringfamilyName, intstyle){2 return newTypeface(nativeCreate(familyName,style));
3}
4
5 public staticTypefacecreate(Typefacefamily, intstyle){
6 intni=0;
7 if(family!= null){
8ni=family.native_instance;
9}
10 return newTypeface(nativeCreateFromTypeface(ni,style));
11}
12
13
14 public staticTypefacecreateFromAsset(AssetManagermgr,Stringpath){
15 return newTypeface(nativeCreateFromAsset(mgr,path));
16}
17
18 public staticTypefacecreateFromFile(Filepath){
19 return newTypeface(nativeCreateFromFile(path.getAbsolutePath()));
20}
21
22 public staticTypefacecreateFromFile(Stringpath){
23 return newTypeface(nativeCreateFromFile(path));
24}
我们这里使用方法如下:
1Typefacetypeface=Typeface.createFromAsset(getAssets(),"font/Flubber.ttf");2
3TextViewview=(TextView)findViewById(R.id.font_test);
4view.setTypeface(typeface);
效果图片如下
字体文件代码在附件中
/Files/cody1988/android/FontTest.zip
更多相关文章
- Android SD卡创建文件和文件夹失败
- android中使用线程池和临时缓存优化网络图片加载
- 【Android】“存储”之普通文件存储(内部存储空间)
- Android通过加载其他应用的Dex文件破解关键数据
- android中javah生成jni头文件报错问题
- 双击运行Android模拟器、创建SDcard、AVD、安装APK文件、上传文