Download presentation
Presentation is loading. Please wait.
1
Cleveland State University
9 Android Fonts Victor Matos Cleveland State University Notes are based on: The Busy Coder's Guide to Android Development by Mark L. Murphy Copyright © CommonsWare, LLC. ISBN: & Android Developers
2
Fonts Android naturally provides three fonts:
9. Android – UI – Fonts Fonts Android naturally provides three fonts: sans: An m is wider than i, mmm iiii serif: An m is wider than i, mmm iiii monospaced: An mmm is not wider than iii 2
3
Fonts Also know as: Grotesque or Gothic Roman Type
9. Android – UI – Fonts Fonts Also know as: Grotesque or Gothic Roman Type Source: 3
4
9. Android – UI – Fonts Fonts Developers may add any font to their application by following the next steps: Create the /fonts folder in the /assets directory. Copy any fonts you plan to use into the new folder. Use Java code to bind the font with the UI widget wanting to display the custom typeface (see example). 4
5
Original font taken from c:\Windows\Fonts
9. Android – UI – Fonts Fonts Example: Getting ready to use the Jokerman.TTF font. Original font taken from c:\Windows\Fonts 5
6
9. Android – UI – Fonts Fonts Example: Display the Hello World ! message using different fonts. Using the font: Jokerman.TTF Note: If you are using Windows XP look into the folder: c:\Windows\Fonts for fonts installed in your machine. Consult the page: for additional information in manipulating fonts. 6
7
Fonts Example Application: Showing different FONT types.
9. Android – UI – Fonts Fonts Example Application: Showing different FONT types. <?xml version="1.0" encoding="utf-8"?> <TableLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:stretchColumns="1" xmlns:android=" > 7
8
Fonts <TableRow android:id="@+id/myRow1"
9. Android – UI – Fonts Fonts <TableRow android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <TextView android:layout_width="wrap_content" android:background="#ff006666" android:layout_marginRight="24px" android:text="sans:" android:textSize="20sp" </TextView> android:text="Hello, world!" android:typeface="sans" </TableRow> 8
9
Fonts </TableRow> <TableRow android:id="@+id/myRow2"
9. Android – UI – Fonts Fonts </TableRow> <TableRow android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <TextView android:layout_width="wrap_content" android:layout_marginRight="24px" android:text="serif:" android:textSize="20sp" android:background="#ff006666" </TextView> android:text="Hello, world!" android:typeface="serif" 9
10
Fonts <TableRow android:id="@+id/myRow3"
9. Android – UI – Fonts Fonts <TableRow android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <TextView android:layout_width="wrap_content" android:layout_marginRight="24px" android:text="monospace:" android:textSize="20sp" android:background="#ff006666" </TextView> android:text="Hello, world!" android:typeface="monospace" </TableRow> 10
11
To be displayed using a custom font
9. Android – UI – Fonts Fonts <TableRow android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <TextView android:layout_width="wrap_content" android:layout_marginRight="24px" android:text="custom:" android:textSize="20sp" android:background="#ff006666" </TextView> android:text="Hello, world!" </TableRow> </TableLayout> To be displayed using a custom font 11
12
Fonts package cis493.androfontsdemo; import android.app.Activity;
9. Android – UI – Fonts Fonts package cis493.androfontsdemo; import android.app.Activity; import android.graphics.Typeface; import android.os.Bundle; import android.widget.TextView; public class AndroFontDemo extends Activity { @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.main); // bind the "custom" textview with chosen font TextView tvCustom=(TextView)findViewById(R.id.custom); Typeface myNewFace=Typeface.createFromAsset( getAssets(), "fonts/Jokerman.TTF“ ); tvCustom.setTypeface(myNewFace); } 12
13
09 - Android – UI – Fonts Fonts Questions ? 13 13
Similar presentations
© 2025 SlidePlayer.com Inc.
All rights reserved.