android点滴(29) android中设置用户自定义的字体
16lz
2022-05-01
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
更多相关文章
- AIDL --- Android中的远程接口(1)
- Android应用Preference相关及源码浅析(SharePreferences篇)
- 从Android到React Native开发(二、通信与模块实现)
- Android(安卓)SD卡创建文件和文件夹失败
- Android:最全面的 Webview 详解
- Android之Adapter:连接后端数据和前端显示的适配器接口
- Android(安卓)ADB使用方法
- android app签名(debug和release)
- NPM 和webpack 的基础使用