Android 自訂字型 例子

來源:互聯網
上載者:User

標籤:des   android   style   blog   http   io   os   ar   java   

1.選擇你喜歡的字型,下載字型檔

字型參考:http://www.creativebloq.com/graphic-design-tips/best-free-fonts-for-designers-1233380

2.項目assets檔案中建立font檔案夾,將你的字型檔放在該檔案夾中


3.項目代碼

布局代碼:

[html] view plaincopy
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <LinearLayout  
  3.     xmlns:android="http://schemas.android.com/apk/res/android"  
  4.     android:orientation="vertical"  
  5.     android:layout_width="fill_parent"  
  6.     android:layout_height="fill_parent">  
  7.     <TextView  
  8.         android:id="@+id/DefaultFontText"  
  9.         android:layout_width="fill_parent"  
  10.         android:layout_height="wrap_content"  
  11.         android:textSize="30sp"  
  12.         android:text="Here is some text." />  
  13.     <TextView  
  14.         android:id="@+id/CustomFontText"  
  15.         android:layout_width="wrap_content"  
  16.         android:layout_height="wrap_content"  
  17.         android:textSize="30sp"  
  18.         android:text="Here is some text.">  
  19.         </TextView>  
  20. </LinearLayout>  

activity代碼:

[java] view plaincopy
  1. public class Main extends Activity {  
  2.     @Override  
  3.     public void onCreate(Bundle savedInstanceState) {  
  4.         super.onCreate(savedInstanceState);  
  5.         setContentView(R.layout.main);  
  6.    
  7.         Typeface tf = Typeface.createFromAsset(getAssets(),  
  8.                 "fonts/BPreplay.otf");  
  9.         TextView tv = (TextView) findViewById(R.id.CustomFontText);  
  10.         tv.setTypeface(tf);  
  11.     }  
  12. }  

4.


5.源連結

http://www.barebonescoder.com/2010/05/android-development-using-custom-fonts/

Android 自訂字型 例子

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.