Skip to content

Most visited

Recently visited

navigation
Added in API level 1

Typeface

public class Typeface
extends Object

java.lang.Object
   ↳ android.graphics.Typeface


The Typeface class specifies the typeface and intrinsic style of a font. This is used in the paint, along with optionally Paint settings like textSize, textSkewX, textScaleX to specify how text appears when drawn (and measured).

Summary

Constants

int BOLD

int BOLD_ITALIC

int ITALIC

int NORMAL

Fields

public static final Typeface DEFAULT

The default NORMAL typeface object

public static final Typeface DEFAULT_BOLD

The default BOLD typeface object.

public static final Typeface MONOSPACE

The NORMAL style of the default monospace typeface.

public static final Typeface SANS_SERIF

The NORMAL style of the default sans serif typeface.

public static final Typeface SERIF

The NORMAL style of the default serif typeface.

Public methods

static Typeface create(String familyName, int style)

Create a typeface object given a family name, and option style information.

static Typeface create(Typeface family, int style)

Create a typeface object that best matches the specified existing typeface and the specified Style.

static Typeface createFromAsset(AssetManager mgr, String path)

Create a new typeface from the specified font data.

static Typeface createFromFile(String path)

Create a new typeface from the specified font file.

static Typeface createFromFile(File path)

Create a new typeface from the specified font file.

static Typeface defaultFromStyle(int style)

Returns one of the default typeface objects, based on the specified style

boolean equals(Object o)

Compares this instance with the specified object and indicates if they are equal.

int getStyle()

Returns the typeface's intrinsic style attributes

int hashCode()

Returns an integer hash code for this object.

final boolean isBold()

Returns true if getStyle() has the BOLD bit set.

final boolean isItalic()

Returns true if getStyle() has the ITALIC bit set.

Protected methods

void finalize()

Invoked when the garbage collector has detected that this instance is no longer reachable.

Inherited methods

From class java.lang.Object

Constants

BOLD

Added in API level 1
int BOLD

Constant Value: 1 (0x00000001)

BOLD_ITALIC

Added in API level 1
int BOLD_ITALIC

Constant Value: 3 (0x00000003)

ITALIC

Added in API level 1
int ITALIC

Constant Value: 2 (0x00000002)

NORMAL

Added in API level 1
int NORMAL

Constant Value: 0 (0x00000000)

Fields

DEFAULT

Added in API level 1
Typeface DEFAULT

The default NORMAL typeface object

DEFAULT_BOLD

Added in API level 1
Typeface DEFAULT_BOLD

The default BOLD typeface object. Note: this may be not actually be bold, depending on what fonts are installed. Call getStyle() to know for sure.

MONOSPACE

Added in API level 1
Typeface MONOSPACE

The NORMAL style of the default monospace typeface.

SANS_SERIF

Added in API level 1
Typeface SANS_SERIF

The NORMAL style of the default sans serif typeface.

SERIF

Added in API level 1
Typeface SERIF

The NORMAL style of the default serif typeface.

Public methods

create

Added in API level 1
Typeface create (String familyName, 
                int style)

Create a typeface object given a family name, and option style information. If null is passed for the name, then the "default" font will be chosen. The resulting typeface object can be queried (getStyle()) to discover what its "real" style characteristics are.

Parameters
familyName String: May be null. The name of the font family.
style int: The style (normal, bold, italic) of the typeface. e.g. NORMAL, BOLD, ITALIC, BOLD_ITALIC
Returns
Typeface The best matching typeface.

create

Added in API level 1
Typeface create (Typeface family, 
                int style)

Create a typeface object that best matches the specified existing typeface and the specified Style. Use this call if you want to pick a new style from the same family of an existing typeface object. If family is null, this selects from the default font's family.

Parameters
family Typeface: May be null. The name of the existing type face.
style int: The style (normal, bold, italic) of the typeface. e.g. NORMAL, BOLD, ITALIC, BOLD_ITALIC
Returns
Typeface The best matching typeface.

createFromAsset

Added in API level 1
Typeface createFromAsset (AssetManager mgr, 
                String path)

Create a new typeface from the specified font data.

Parameters
mgr AssetManager: The application's asset manager
path String: The file name of the font data in the assets directory
Returns
Typeface The new typeface.

createFromFile

Added in API level 4
Typeface createFromFile (String path)

Create a new typeface from the specified font file.

Parameters
path String: The full path to the font data.
Returns
Typeface The new typeface.

createFromFile

Added in API level 4
Typeface createFromFile (File path)

Create a new typeface from the specified font file.

Parameters
path File: The path to the font data.
Returns
Typeface The new typeface.

defaultFromStyle

Added in API level 1
Typeface defaultFromStyle (int style)

Returns one of the default typeface objects, based on the specified style

Parameters
style int
Returns
Typeface the default typeface that corresponds to the style

equals

Added in API level 1
boolean equals (Object o)

Compares this instance with the specified object and indicates if they are equal. In order to be equal, o must represent the same object as this instance using a class-specific comparison. The general contract is that this comparison should be reflexive, symmetric, and transitive. Also, no object reference other than null is equal to null.

The default implementation returns true only if this == o. See Writing a correct equals method if you intend implementing your own equals method.

The general contract for the equals and hashCode() methods is that if equals returns true for any two objects, then hashCode() must return the same value for these objects. This means that subclasses of Object usually override either both methods or neither of them.

Parameters
o Object: the object to compare this instance with.
Returns
boolean true if the specified object is equal to this Object; false otherwise.

getStyle

Added in API level 1
int getStyle ()

Returns the typeface's intrinsic style attributes

Returns
int

hashCode

Added in API level 1
int hashCode ()

Returns an integer hash code for this object. By contract, any two objects for which equals(Object) returns true must return the same hash code value. This means that subclasses of Object usually override both methods or neither method.

Note that hash values must not change over time unless information used in equals comparisons also changes.

See Writing a correct hashCode method if you intend implementing your own hashCode method.

Returns
int this object's hash code.

isBold

Added in API level 1
boolean isBold ()

Returns true if getStyle() has the BOLD bit set.

Returns
boolean

isItalic

Added in API level 1
boolean isItalic ()

Returns true if getStyle() has the ITALIC bit set.

Returns
boolean

Protected methods

finalize

Added in API level 1
void finalize ()

Invoked when the garbage collector has detected that this instance is no longer reachable. The default implementation does nothing, but this method can be overridden to free resources.

Note that objects that override finalize are significantly more expensive than objects that don't. Finalizers may be run a long time after the object is no longer reachable, depending on memory pressure, so it's a bad idea to rely on them for cleanup. Note also that finalizers are run on a single VM-wide finalizer thread, so doing blocking work in a finalizer is a bad idea. A finalizer is usually only necessary for a class that has a native peer and needs to call a native method to destroy that peer. Even then, it's better to provide an explicit close method (and implement Closeable), and insist that callers manually dispose of instances. This works well for something like files, but less well for something like a BigInteger where typical calling code would have to deal with lots of temporaries. Unfortunately, code that creates lots of temporaries is the worst kind of code from the point of view of the single finalizer thread.

If you must use finalizers, consider at least providing your own ReferenceQueue and having your own thread process that queue.

Unlike constructors, finalizers are not automatically chained. You are responsible for calling super.finalize() yourself.

Uncaught exceptions thrown by finalizers are ignored and do not terminate the finalizer thread. See Effective Java Item 7, "Avoid finalizers" for more.

Throws
Throwable
This site uses cookies to store your preferences for site-specific language and display options.

Hooray!

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.