Android 自定义字体样式 及系统默认字体样式 的设置
来源:互联网 发布:adobe cc 2017 mac 编辑:程序博客网 时间:2024/05/22 09:44
Android 能添加文字的控件都可以设置字体样式
关键字是:Typeface 在Java代码中设置或者在xml文件里面设置都可以
Android系统默认给出四种样式的字体 , 分别是 : Nomal Monospace Sans Serif
要想使用自定义的字体样式先要从网上下载一个 .tty 格式的字体文件
然后粘贴到项目里面 , 具体步骤如下 :
一 工作区间切换到 Project区间 在 app src main 下新建包 assets
再新建fonts文件夹 然后把文件粘贴进去
最终效果如下:
OK
然后这个是 MainActivity代码:
private String path; private TextView tv; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); tv = (TextView) findViewById(R.id.tv); path = "fonts" + File.separator + "lcnd.ttf"; AssetManager manager = this.getAssets(); Typeface font = Typeface.createFromAsset(manager , path); tv.setTypeface(font); }
下面是Xml代码:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context="com.example.administrator.hongyangzv.MainActivity"> <TextView android:gravity="center" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:text="Nomal字体" android:textSize="30dp" android:typeface="normal"/> <TextView android:gravity="center" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:text="Monospace字体" android:textSize="30dp" android:typeface="monospace"/> <TextView android:gravity="center" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:text="Sans字体" android:textSize="30dp" android:typeface="sans"/> <TextView android:gravity="center" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:text="Serif字体" android:textSize="30dp" android:typeface="serif"/> <TextView android:id="@+id/tv" android:gravity="center" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:text="自定义字体 - 250" android:textSize="30dp"/></LinearLayout>
----------------------------------------------搞定收工!!!---------------------------------------
切记:路径名字一定要正确, 第一次犯傻 , 浪费一上午 也没找到是哪里出的错!!!被自己气哭了
阅读全文
4 0
- Android 自定义字体样式 及系统默认字体样式 的设置
- #Android 自定义字体样式
- Android 自定义字体样式
- android自定义字体样式
- android 自定义字体样式
- android 自定义字体样式
- axure中默认字体样式的设置
- android设置字体样式
- android设置字体样式
- 字体样式的设置
- iOS 获取系统的字体及样式
- android TextView自定义字体样式
- android设置各种字体样式
- Android TextView字体样式设置
- 添加自定义的 字体样式
- 默认Web字体样式
- 默认Web字体样式
- 默认Web字体样式
- c语言计算文件大小
- epoll机制:epoll_create、epoll_ctl、epoll_wait、close
- 金山的笔试题总结
- Swift 中的协议 (Protocol)
- 设计模式之适配器模式
- Android 自定义字体样式 及系统默认字体样式 的设置
- Zookeeper 是什么
- C#梳理【类的继承和Interface接口】
- javac -home不是内部或外部命令
- warning LNK4099: PDB 原因及解决方案
- 面向对象
- Hibernate中一对多关联关系保存
- SpringBoot HTML 报错404
- 系统学习深度学习(三十八)--CRAFT