Android字型設定,Roboto字型使用

來源:互聯網
上載者:User

標籤:android

一、自訂字型

1.android Typeface使用TTF字型檔設定字型

我們可以在程式中放入ttf字型檔,在程式中使用Typeface設定字型。
第一步,在assets目錄下建立fonts目錄,把ttf字型檔放到這。
第二步,程式中調用:

[java] view plaincopy

  1. AssetManager mgr=getAssets();//得到AssetManager  

  2.   

  3. Typeface tf=Typeface.createFromAsset(mgr, "fonts/ttf.ttf");//根據路徑得到Typeface  

  4.   

  5. tv=findViewById(R.id.textview);  

  6.   

  7. tv.setTypeface(tf);//設定字型  


2.在xml檔案中使用android:textStyle=”bold” 可以將英文設定成粗體, 但是不能將中文設定成粗體,
將中文設定成粗體的方法是: 


[java] view plaincopy

  1. TextView tv = (TextView)findViewById(R.id.TextView01);   

  2. tv.getPaint().setFakeBoldText(true);//中文仿“粗體”--使用TextPaint的仿“粗體”設定setFakeBoldText為true。  


    注意:部分字型中文無效,雖然不會報錯,但是對中文無效。二、使用RoBoto

自從Android4.0後預設字型就使用了Roboto,下面介紹一下使用方法:



[java] view plaincopy

  1. android:fontFamily="sans-serif" // roboto regular  

  2. android:fontFamily="sans-serif-light" // roboto light  

  3. android:fontFamily="sans-serif-condensed" // roboto condensed  

  4. android:fontFamily="sans-serif-thin" // roboto thin (android 4.2)  

  5. //in combination with  

  6. android:textStyle="normal|bold|italic"  


可用的參數:

Regular
Italic
Bold
Bold-italic
Light
Light-italic
Thin
Thin-italic
Condensed regular
Condensed italic
Condensed bold
Condensed bold-italic


其他精彩文章文章

Android KSOAP2調用.net webservicejQuery教程(8)-DOM樹操作之使用反向插入方法android學習筆記(34)使用AlertDialog建立簡單對話方塊android學習筆記(33)畫廊視圖(Gallery)的功能和用法android navidgation drawer 在隱藏式瀏覽選單中如何改變List選中項的...


更多關於android開發文章


本文出自 “萌萌的it人” 部落格,請務必保留此出處http://jlins.blog.51cto.com/4487484/1599257

Android字型設定,Roboto字型使用

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.