Android Custom Font Examples

Source: Internet
Author: User

1. Select the font you like and download the font file

Font reference: http://www.creativebloq.com/graphic-design-tips/best-free-fonts-for-designers-1233380

2. Create a new font folder in the project assets file and place your font file in the folder


3. Project Code

Layout code:

[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 code:

[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. Typeface tf = Typeface.createfromasset (Getassets (),
  7. "FONTS/BPREPLAY.OTF");
  8. TextView TV = (TextView) Findviewbyid (R.id.customfonttext);
  9. Tv.settypeface (TF);
  10. }
  11. }

4.


5. SOURCE Link

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

Android Custom Font Examples

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.