导航:首页 > 操作系统 > 如何应用外部字体安卓

如何应用外部字体安卓

发布时间:2022-12-27 07:58:10

1. 如何在android开发中使用自定义的字体库

1、Android系统默认支持三种字体,分别为:“sans”, “serif”, “monospace
2、在Android中可以引入其他字体 。
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:Android="http://schemas.android.com/apk/res/android"
Android:layout_width="fill_parent"
Android:layout_height="fill_parent" >

<TableRow>

<TextView
Android:layout_marginRight="4px"
Android:text="sans:"
Android:textSize="20sp" >
</TextView>
<!-- 使用默认的sans字体 -->

<TextView
Android:id="@+id/sans"
Android:text="Hello,World"
Android:textSize="20sp"
Android:typeface="sans" >
</TextView>
</TableRow>

<TableRow>

<TextView
Android:layout_marginRight="4px"
Android:text="serif:"
Android:textSize="20sp" >
</TextView>
<!-- 使用默认的serifs字体 -->

<TextView
Android:id="@+id/serif"
Android:text="Hello,World"
Android:textSize="20sp"
Android:typeface="serif" >
</TextView>
</TableRow>

<TableRow>

<TextView
Android:layout_marginRight="4px"
Android:text="monospace:"
Android:textSize="20sp" >
</TextView>
<!-- 使用默认的monospace字体 -->

<TextView
Android:id="@+id/monospace"
Android:text="Hello,World"
Android:textSize="20sp"
Android:typeface="monospace" >
</TextView>
</TableRow>
<!-- 这里没有设定字体,我们将在Java代码中设定 -->

<TableRow>

<TextView
Android:layout_marginRight="4px"
Android:text="custom:"
Android:textSize="20sp" >
</TextView>

<TextView
Android:id="@+id/custom"
Android:text="Hello,World"
Android:textSize="20sp" >
</TextView>
</TableRow>

</TableLayout>
// 得到TextView控件对象
TextView textView = (TextView) findViewById(R.id.custom);
// 将字体文件保存在assets/fonts/目录下,www.linuxidc.com创建Typeface对象
Typeface typeFace = Typeface.createFromAsset(getAssets(),"fonts/DroidSansThai.ttf");
// 应用字体
textView.setTypeface(typeFace);
如果想对整个界面的所有控件都应用自定义字体,可以:

package arui.blog.csdn.NET;
import android.app.Activity;
import android.graphics.Typeface;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class FontManager {
public static void changeFonts(ViewGroup root, Activity act) {
Typeface tf = Typeface.createFromAsset(act.getAssets(),
"fonts/xxx.ttf");
for (int i = 0; i < root.getChildCount(); i++) {
View v = root.getChildAt(i);
if (v instanceof TextView) {
((TextView) v).setTypeface(tf);
} else if (v instanceof Button) {
((Button) v).setTypeface(tf);
} else if (v instanceof EditText) {
((EditText) v).setTypeface(tf);
} else if (v instanceof ViewGroup) {
changeFonts((ViewGroup) v, act);
}
}
}
}

2. 安卓系统怎么更换字体

1、首先在安卓手机上下载字体管家软件,搜索直接安装即可。

3. 怎样设置安卓系统手机上的字体啊

1、首先我们进入设置,如图所示。

阅读全文

与如何应用外部字体安卓相关的资料

热点内容
压缩活动轨迹 浏览:672
6米梁加密筋 浏览:77
怎么学好ps如何学好编程 浏览:298
c编译器厂商 浏览:112
简述编译程序以及解释程序 浏览:1
linux升级kernel 浏览:176
入侵服务器挖矿是什么罪 浏览:46
房屋解压资料丢了怎么办 浏览:808
java文件行读写 浏览:544
影城网上售票系统源码 浏览:634
防疫就是命令歌曲 浏览:204
滴滴号码加密怎么解除 浏览:844
模具编程的职责 浏览:944
华为ssh改加密算法 浏览:149
文件夹空白合同 浏览:763
pythonwebpy开发 浏览:671
不是c编译器的有 浏览:662
win10压缩包下载 浏览:905
逆战手机app怎么样 浏览:948
自嗨自我解压图片 浏览:397