Android APIs
public final class

Icon

extends Object
implements Parcelable
java.lang.Object
   ↳ android.graphics.drawable.Icon

Class Overview

An umbrella container for several serializable graphics representations, including Bitmaps, compressed bitmap images (e.g. JPG or PNG), and drawable resources (including vectors). Much ink has been spilled on the best way to load images, and many clients may have different needs when it comes to threading and fetching. This class is therefore focused on encapsulation rather than behavior.

Summary

Nested Classes
interface Icon.OnDrawableLoadedListener Implement this interface to receive a callback when loadDrawableAsync is finished and your Drawable is ready. 
[Expand]
Inherited Constants
From interface android.os.Parcelable
Fields
public static final Creator<Icon> CREATOR
Public Methods
static Icon createWithBitmap(Bitmap bits)
Create an Icon pointing to a bitmap in memory.
static Icon createWithContentUri(String uri)
Create an Icon pointing to an image file specified by URI.
static Icon createWithContentUri(Uri uri)
Create an Icon pointing to an image file specified by URI.
static Icon createWithData(byte[] data, int offset, int length)
Create an Icon pointing to a compressed bitmap stored in a byte array.
static Icon createWithFilePath(String path)
Create an Icon pointing to an image file specified by path.
static Icon createWithResource(Context context, int resId)
Create an Icon pointing to a drawable resource.
static Icon createWithResource(String resPackage, int resId)
Create an Icon pointing to a drawable resource.
int describeContents()
Parcelable interface
Drawable loadDrawable(Context context)
Returns a Drawable that can be used to draw the image inside this Icon, constructing it if necessary.
void loadDrawableAsync(Context context, Icon.OnDrawableLoadedListener listener, Handler handler)
Invokes loadDrawable(Context) on a background thread and then runs andThen on the UI thread when finished.
void loadDrawableAsync(Context context, Message andThen)
Invokes loadDrawable(Context) on the given Handler and then sends andThen to the same Handler when finished.
Icon setTint(int tint)
Store a color to use whenever this Icon is drawn.
Icon setTintList(ColorStateList tintList)
Store a color to use whenever this Icon is drawn.
Icon setTintMode(PorterDuff.Mode mode)
Store a blending mode to use whenever this Icon is drawn.
String toString()
Returns a string containing a concise, human-readable description of this object.
void writeToParcel(Parcel dest, int flags)
Flatten this object in to a Parcel.
[Expand]
Inherited Methods
From class java.lang.Object
From interface android.os.Parcelable

Fields

public static final Creator<Icon> CREATOR

Added in API level 23

Public Methods

public static Icon createWithBitmap (Bitmap bits)

Added in API level 23

Create an Icon pointing to a bitmap in memory.

Parameters
bits A valid Bitmap object

public static Icon createWithContentUri (String uri)

Added in API level 23

Create an Icon pointing to an image file specified by URI.

Parameters
uri A uri referring to local content:// or file:// image data.

public static Icon createWithContentUri (Uri uri)

Added in API level 23

Create an Icon pointing to an image file specified by URI.

Parameters
uri A uri referring to local content:// or file:// image data.

public static Icon createWithData (byte[] data, int offset, int length)

Added in API level 23

Create an Icon pointing to a compressed bitmap stored in a byte array.

Parameters
data Byte array storing compressed bitmap data of a type that BitmapFactory can decode (see Bitmap.CompressFormat).
offset Offset into data at which the bitmap data starts
length Length of the bitmap data

public static Icon createWithFilePath (String path)

Added in API level 23

Create an Icon pointing to an image file specified by path.

Parameters
path A path to a file that contains compressed bitmap data of a type that BitmapFactory can decode.

public static Icon createWithResource (Context context, int resId)

Added in API level 23

Create an Icon pointing to a drawable resource.

Parameters
context The context for the application whose resources should be used to resolve the given resource ID.
resId ID of the drawable resource

public static Icon createWithResource (String resPackage, int resId)

Added in API level 23

Create an Icon pointing to a drawable resource.

Parameters
resPackage Name of the package containing the resource in question
resId ID of the drawable resource

public int describeContents ()

Added in API level 23

Parcelable interface

Returns
  • a bitmask indicating the set of special object types marshalled by the Parcelable.

public Drawable loadDrawable (Context context)

Added in API level 23

Returns a Drawable that can be used to draw the image inside this Icon, constructing it if necessary. Depending on the type of image, this may not be something you want to do on the UI thread, so consider using loadDrawableAsync instead.

Parameters
context Context in which to load the drawable; used to access Resources, for example.
Returns
  • A fresh instance of a drawable for this image, yours to keep.

public void loadDrawableAsync (Context context, Icon.OnDrawableLoadedListener listener, Handler handler)

Added in API level 23

Invokes loadDrawable(Context) on a background thread and then runs andThen on the UI thread when finished.

Parameters
context Context in which to load the drawable; see loadDrawable(Context)
listener a callback to run on the provided
handler Handler on which to run andThen.

public void loadDrawableAsync (Context context, Message andThen)

Added in API level 23

Invokes loadDrawable(Context) on the given Handler and then sends andThen to the same Handler when finished.

Parameters
context Context in which to load the drawable; see loadDrawable(Context)
andThen Message to send to its target once the drawable is available. The obj property is populated with the Drawable.

public Icon setTint (int tint)

Added in API level 23

Store a color to use whenever this Icon is drawn.

Parameters
tint a color, as in setTint(int)
Returns
  • this same object, for use in chained construction

public Icon setTintList (ColorStateList tintList)

Added in API level 23

Store a color to use whenever this Icon is drawn.

Parameters
tintList as in setTintList(ColorStateList), null to remove tint
Returns
  • this same object, for use in chained construction

public Icon setTintMode (PorterDuff.Mode mode)

Added in API level 23

Store a blending mode to use whenever this Icon is drawn.

Parameters
mode a blending mode, as in setTintMode(PorterDuff.Mode), may be null
Returns
  • this same object, for use in chained construction

public String toString ()

Added in API level 23

Returns a string containing a concise, human-readable description of this object. Subclasses are encouraged to override this method and provide an implementation that takes into account the object's type and data. The default implementation is equivalent to the following expression:

   getClass().getName() + '@' + Integer.toHexString(hashCode())

See Writing a useful toString method if you intend implementing your own toString method.

Returns
  • a printable representation of this object.

public void writeToParcel (Parcel dest, int flags)

Added in API level 23

Flatten this object in to a Parcel.

Parameters
dest The Parcel in which the object should be written.
flags Additional flags about how the object should be written. May be 0 or PARCELABLE_WRITE_RETURN_VALUE.