Android 控制項設定字型 Typeface

2021-07-25 20:49:46 字數 1634 閱讀 1285

這裡是以textview為例,其他顯示文字的控制項通用

typeface.default //常規字型型別

typeface.default_bold //黑體字體型別

typeface.monospace //等寬字型型別

typeface.serif //襯線字型型別

typeface.sans_serif //無襯線體字型型別

typeface.bold //粗體

typeface.bold_italic //粗斜體

typeface.italic //斜體

typeface.normal //常規

使用android:typeface來設定:

android:typeface=」sans」
有兩種建立字型的方式:

1)

typeface create (typeface family, 

int style)

family為(1)中常用的字型型別;

style為(2)常用的字型風格

eg1:

typeface font = typeface.create(typeface.sans_serif, typeface.bold);

p.settypeface( font );

2)

typeface create (string familyname, 

int style)

familyname 為(1)中常用的字型名稱;

style為(2)常用的字型風格

eg2:

string familyname = 「宋體」;

typeface font = typeface.create(familyname,typeface.bold);

p.settypeface(font);

3)如果依然使用預設字型,僅僅改變字型風格

typeface mtypeface = typeface.defaultfromstyle(typeface.italic);
typeface face = typeface.createfromasset(getassets(), "fonts/hanyi.ttf");

//title是之間定義的控制項

title.settypeface(face);

2)將.ttf字型庫拷貝到sd卡上可以通過createfromfile(string path)和createfromfile(file path)

//在實際使用中,字型庫可能存在於sd卡上,可以採用createfromfile()來替代createfromasset。

string path = "/hpdata/fonts/hwapu-microhei+diy.ttf";

file file = new file(path);

if (file.exists())

//或者使用createfromfile(string path)

try catch (exception e)

Android 字型設定

android 對中文字型支援很不好 需要加入相應的字型庫 1 建立布局layout 建立線性布局 linearlayout linearlayout newlinearlayout this 設定線性布局為垂直方向 linearlayout.setorientation linearlayout....

android 設定控制項的顏色字型的方法

android平台已經給我們提供了很多標準的元件,如 textview editview button imageview menu等,還有許多布局控制項,常見的有 absolutelayout linerlayout relativelayout tablelayout等。但隨著人們對視覺的需求,...

Android設定TextView字型

1.將字型檔案 例如hyliangpinxiancuj.ttf 放到assets目錄下 2.自定義multifonttextview繼承textview public class multifonttextview extends textview 初始化字型 param context priva...