Wednesday, May 4, 2011

Using Custom Fonts

By Magesh Kumar   Posted at  3:13 AM   Android No comments


Lastly we’re going to examine the process of using custom fonts. We’ll use this font for demonstration purposes. Download it and place the TTF file in the ./assets directory (create it if it doesn’t exist yet).


We’re going to use a basic layout file with a TextView, marked with an id of “custom_font” so we can access it in our code.
<?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/custom_font"

            android:layout_width="fill_parent"

            android:layout_height="wrap_content"

            android:text="This is the Chantelli Antiqua font."

            />

 

</LinearLayout>


Open your main activity file and insert this into the onCreate() method:
TextView txt = (TextView) findViewById(R.id.custom_font);

        Typeface font = Typeface.createFromAsset(getAssets(), "Chantelli_Antiqua.ttf");

        txt.setTypeface(font);

About the Author

Nulla sagittis convallis arcu. Sed sed nunc. Curabitur consequat. Quisque metus enim, venenatis fermentum, mollis in, porta et, nibh. Duis vulputate elit in elit. Mauris dictum libero id justo.
View all posts by: BT9

0 comments:

Back to top ↑
Connect with Us

What they says

© 2013 MaGeSH 2 help. WP Mythemeshop Converted by BloggerTheme9
Blogger templates. Proudly Powered by Blogger.