Android開發 更換字型

2021-08-03 00:27:47 字數 1154 閱讀 8210

引入字型檔案.png

1、一般情況下,只針對部分字型,或者某個介面的少量字型進行修改

在xml布局中,不做任何修改:

在**中:

得到textview物件

textview textview =(textview)findviewbyid(r.id.textview);
建立typeface物件

typeface typeface =typeface.createfromasset(getassets(),"fonts/roboto-light.ttf");
設定字型

textview.settypeface(typeface);
簡單的三步,搞定。

public final class fontsoverride 

protected static void replacefont(string statictypefacefieldname,

final typeface newtypeface) catch (nosuchfieldexception e) catch (illegalacces***ception e) }}

@override

public void oncreate()

}

public class customtextview extends textview 

public customtextview(context context, attributeset attrs)

public customtextview(context context)

private void init()

}

xml中使用自定義的customtextview

總結:如果使用android系統提供字型,直接在xml布局中設定textview的typeface;

如果使用自定義字型,則根據具體需求,選擇對應的方法

Android 如何更換系統字型

android系統的所有字型都放在 system fonts 下面。有二種方法可以修改。1.第一種是直接替換預設的字型檔案 droidsans ttf 預設數字和英文本型 無特殊格式 droidsans bold.ttf 預設數字和英文粗體 無特殊格式 droidsansfallback.ttf 預...

Android 使用反射更換app全部字型

一 自定義類繼承 public static typeface typeface override public void oncreate public void settypeface catch nosuchfieldexception e catch illegalacces ception...

Ubuntu更換系統字型

瀏覽器輸入 二 字型安裝 1.解壓壓縮包 tar zxvf yaheiconsolas.tar.gz 2.在系統目錄下建立自定義字型目錄 sudo mkdir p usr share fonts vista 3.複製解壓出來的字型到剛才建立的目錄 sudo cp yaheiconsolas.ttf ...