標籤: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
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent">
- <TextView
- android:id="@+id/DefaultFontText"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:textSize="30sp"
- android:text="Here is some text." />
- <TextView
- android:id="@+id/CustomFontText"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:textSize="30sp"
- android:text="Here is some text.">
- </TextView>
- </LinearLayout>
activity代碼:
[java] view plaincopy
- public class Main extends Activity {
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
-
- Typeface tf = Typeface.createFromAsset(getAssets(),
- "fonts/BPreplay.otf");
- TextView tv = (TextView) findViewById(R.id.CustomFontText);
- tv.setTypeface(tf);
- }
- }
4.
5.源連結
http://www.barebonescoder.com/2010/05/android-development-using-custom-fonts/
Android 自訂字型 例子