Android 下不同格式字体的实现方法
来源:互联网 发布:淘宝手机详情尺寸大小 编辑:程序博客网 时间:2024/06/14 16:51
从师兄那里看到了android 界面不同格式字体的实现方法,记录下来以便以后查看。
首先在Android Studio中建立assets文件夹,在assets文件夹下建立fonts文件夹,然后将字体文件.ttf文件拷贝至fonts文件夹下。
在android studio中建立assets文件夹的方法:在res文件夹傍边点击右键new-->Folder-->AssetsFolder即可;字体文件 .ttf 需要自己下载.实现不同格式的字体,下载对应的ttf文件就好,在windows中可在C:\Windows\Fonts目录下查找需要的.ttf文件.
来看一个不同格式字体的小例子:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/activity_main" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="com.example.chenhy.font.MainActivity"> <TextView android:id="@+id/text1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="30sp" android:text="这是第一种字体!" /> <TextView android:id="@+id/text2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="30sp" android:text="这是第二种字体!" /> <TextView android:id="@+id/text3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="30sp" android:text="这是第三种字体!" /></LinearLayout>
然后mainactivity代码
package com.example.chenhy.font;import android.graphics.Typeface;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.widget.TextView;public class MainActivity extends AppCompatActivity { TextView text1; TextView text2; TextView text3; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); text1 = (TextView)findViewById(R.id.text1); text2 = (TextView)findViewById(R.id.text2); text3 = (TextView)findViewById(R.id.text3); Typeface typeFace1 = Typeface.createFromAsset(getAssets(),"fonts/FZKTJT.ttf"); Typeface typeFace2 = Typeface.createFromAsset(getAssets(),"fonts/FZQTJT.ttf"); Typeface typeFace3 = Typeface.createFromAsset(getAssets(),"fonts/SJT.ttf"); text1.setTypeface(typeFace1); text2.setTypeface(typeFace2); text3.setTypeface(typeFace3); }}
字体效果图
0 0
- Android 下不同格式字体的实现方法
- Android系统下不同字体的环境判断
- C# RichTextBox显示不同格式的字体
- ImageButton不同状态下的实现方法
- Android 不同分辨率下字体自适应大小
- Android实现自定义字体格式液晶数字
- 不同机型下label字体的大小
- 采用不同的方法创建字体
- edit加载不同字体格式
- 实现不同字体颜色的TextView
- (七)利用processing绘制不同格式的字体
- SpannableStringBuilder实现一个控件字体不同的字体风格
- android中TextView与Html结合使用实现字体和颜色的不同,并且换行
- Android使用typeface实现不同字体的调用显示及String转换为Unicode
- 获取不同格式的时间的方法
- Android中使用其他格式的字体
- Android手机在不同分辨率情况下字体自适应大小
- Android手机在不同分辨率情况下字体自适应大小
- AFNetworking到底做了什么
- ToLua 笔记
- 回首,展望
- 在matlab中运用cvx与Mosek
- 线性代数习题求解复习
- Android 下不同格式字体的实现方法
- 欢迎使用CSDN-markdown编辑器
- Android动态破解微信本地数据库(EnMicroMsg.db)
- CI框架常用经典操作类总结(路由,伪静态,分页,session,验证码等)
- 一.机器人概率学笔记_定位
- Android 起始页广告
- 数据库第三方框架FMDB详细讲解
- Linux进程通信之信号
- jquery attr()方法