O segundo Visualização do Desenvolvedor do Android 11 já está disponível, teste e compartilhe seu feedback.

IconCompat

public class IconCompat
extends Object implements VersionedParcelable

java.lang.Object
   ↳ androidx.core.graphics.drawable.IconCompat


Helper for accessing features in Icon.

Summary

Constants

int TYPE_ADAPTIVE_BITMAP

An icon that was created using createWithAdaptiveBitmap(Bitmap).

int TYPE_BITMAP

An icon that was created using createWithBitmap(Bitmap).

int TYPE_DATA

An icon that was created using createWithData(byte[], int, int).

int TYPE_RESOURCE

An icon that was created using createWithResource(Context, int).

int TYPE_UNKNOWN

Value returned when the type of an Icon cannot be determined.

int TYPE_URI

An icon that was created using createWithContentUri(Uri).

int TYPE_URI_ADAPTIVE_BITMAP

An icon that was created using createWithAdaptiveBitmapContentUri(Uri).

Public methods

static IconCompat createFromBundle(Bundle bundle)

Extracts an icon from a bundle that was added using toBundle().

static IconCompat createFromIcon(Context context, Icon icon)

Creates an IconCompat from an Icon.

static IconCompat createWithAdaptiveBitmap(Bitmap bits)

Create an Icon pointing to a bitmap in memory that follows the icon design guideline defined by AdaptiveIconDrawable.

static IconCompat createWithAdaptiveBitmapContentUri(String uri)

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

static IconCompat createWithAdaptiveBitmapContentUri(Uri uri)

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

static IconCompat createWithBitmap(Bitmap bits)

Create an Icon pointing to a bitmap in memory.

static IconCompat createWithContentUri(String uri)

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

static IconCompat createWithContentUri(Uri uri)

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

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

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

static IconCompat createWithResource(Context context, int resId)

Create an Icon pointing to a drawable resource.

int getResId()

Gets the resource id used to create this icon.

String getResPackage()

Gets the package used to create this icon.

int getType()

Gets the type of the icon provided.

Uri getUri()

Gets the uri used to create this icon.

Drawable loadDrawable(Context context)

Returns a Drawable that can be used to draw the image inside this Icon, constructing it if necessary.

void onPostParceling()

Called immediately after this object has been deserialized, can be used to handle any custom fields that cannot be easily annotated.

void onPreParceling(boolean isStream)

Called immediately before this object is going to be serialized, can be used to handle any custom fields that cannot be easily annotated.

IconCompat setTint(int tint)

Store a color to use whenever this Icon is drawn.

IconCompat setTintList(ColorStateList tintList)

Store a color to use whenever this Icon is drawn.

IconCompat setTintMode(PorterDuff.Mode mode)

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

Bundle toBundle()

Adds this Icon to a Bundle that can be read back with the same parameters to createFromBundle(Bundle).

Icon toIcon()

This method is deprecated. Use toIcon(Context) to generate the Icon object.

Icon toIcon(Context context)

Convert this compat object to Icon object.

String toString()

Inherited methods

Constants

TYPE_ADAPTIVE_BITMAP

public static final int TYPE_ADAPTIVE_BITMAP

An icon that was created using createWithAdaptiveBitmap(Bitmap).

Constant Value: 5 (0x00000005)

TYPE_BITMAP

public static final int TYPE_BITMAP

An icon that was created using createWithBitmap(Bitmap).

Constant Value: 1 (0x00000001)

TYPE_DATA

public static final int TYPE_DATA

An icon that was created using createWithData(byte[], int, int).

Constant Value: 3 (0x00000003)

TYPE_RESOURCE

public static final int TYPE_RESOURCE

An icon that was created using createWithResource(Context, int).

Constant Value: 2 (0x00000002)

TYPE_UNKNOWN

public static final int TYPE_UNKNOWN

Value returned when the type of an Icon cannot be determined.

Constant Value: -1 (0xffffffff)

TYPE_URI

public static final int TYPE_URI

An icon that was created using createWithContentUri(Uri).

Constant Value: 4 (0x00000004)

TYPE_URI_ADAPTIVE_BITMAP

public static final int TYPE_URI_ADAPTIVE_BITMAP

An icon that was created using createWithAdaptiveBitmapContentUri(Uri).

Constant Value: 6 (0x00000006)

Public methods

createFromBundle

public static IconCompat createFromBundle (Bundle bundle)

Extracts an icon from a bundle that was added using toBundle().

Parameters
bundle Bundle

Returns
IconCompat

createFromIcon

public static IconCompat createFromIcon (Context context, 
                Icon icon)

Creates an IconCompat from an Icon.

Parameters
context Context

icon Icon

Returns
IconCompat

createWithAdaptiveBitmap

public static IconCompat createWithAdaptiveBitmap (Bitmap bits)

Create an Icon pointing to a bitmap in memory that follows the icon design guideline defined by AdaptiveIconDrawable.

Parameters
bits Bitmap: A valid Bitmap object

Returns
IconCompat

createWithAdaptiveBitmapContentUri

public static IconCompat createWithAdaptiveBitmapContentUri (String uri)

Create an Icon pointing to an image file specified by URI. Image file should follow the icon design guideline defined by AdaptiveIconDrawable.

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

Returns
IconCompat

createWithAdaptiveBitmapContentUri

public static IconCompat createWithAdaptiveBitmapContentUri (Uri uri)

Create an Icon pointing to an image file specified by URI. Image file should follow the icon design guideline defined by AdaptiveIconDrawable.

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

Returns
IconCompat

createWithBitmap

public static IconCompat createWithBitmap (Bitmap bits)

Create an Icon pointing to a bitmap in memory.

Parameters
bits Bitmap: A valid Bitmap object

Returns
IconCompat

createWithContentUri

public static IconCompat createWithContentUri (String uri)

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

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

Returns
IconCompat

createWithContentUri

public static IconCompat createWithContentUri (Uri uri)

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

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

Returns
IconCompat

createWithData

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

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

Parameters
data byte: Byte array storing compressed bitmap data of a type that BitmapFactory can decode (see Bitmap.CompressFormat).

offset int: Offset into data at which the bitmap data starts

length int: Length of the bitmap data

Returns
IconCompat

createWithResource

public static IconCompat createWithResource (Context context, 
                int resId)

Create an Icon pointing to a drawable resource.

Parameters
context Context: The context for the application whose resources should be used to resolve the given resource ID.

resId int: ID of the drawable resource

Returns
IconCompat

getResId

public int getResId ()

Gets the resource id used to create this icon.

Only valid for icons of type TYPE_RESOURCE. Note: This resource may not be available if the application changes at all, and it is up to the caller to ensure safety if this resource is re-used and/or persisted.

Returns
int

getResPackage

public String getResPackage ()

Gets the package used to create this icon.

Only valid for icons of type TYPE_RESOURCE. Note: This package may not be available if referenced in the future, and it is up to the caller to ensure safety if this package is re-used and/or persisted.

Returns
String

getType

public int getType ()

Gets the type of the icon provided.

Note that new types may be added later, so callers should guard against other types being returned.

Returns
int

getUri

public Uri getUri ()

Gets the uri used to create this icon.

Only valid for icons of type TYPE_URI. Note: This uri may not be available in the future, and it is up to the caller to ensure safety if this uri is re-used and/or persisted.

Returns
Uri

loadDrawable

public Drawable loadDrawable (Context context)

Returns a Drawable that can be used to draw the image inside this Icon, constructing it if necessary.

Parameters
context Context: Context in which to load the drawable; used to access Resources, for example.

Returns
Drawable A fresh instance of a drawable for this image, yours to keep.

onPostParceling

public void onPostParceling ()

Called immediately after this object has been deserialized, can be used to handle any custom fields that cannot be easily annotated.

onPreParceling

public void onPreParceling (boolean isStream)

Called immediately before this object is going to be serialized, can be used to handle any custom fields that cannot be easily annotated.

Parameters
isStream boolean

setTint

public IconCompat setTint (int tint)

Store a color to use whenever this Icon is drawn.

Parameters
tint int: a color, as in Drawable.setTint(int)

Returns
IconCompat this same object, for use in chained construction

setTintList

public IconCompat setTintList (ColorStateList tintList)

Store a color to use whenever this Icon is drawn.

Parameters
tintList ColorStateList: as in Drawable.setTintList(ColorStateList), null to remove tint

Returns
IconCompat this same object, for use in chained construction

setTintMode

public IconCompat setTintMode (PorterDuff.Mode mode)

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

Parameters
mode PorterDuff.Mode: a blending mode, as in Drawable.setTintMode(PorterDuff.Mode), may be null

Returns
IconCompat this same object, for use in chained construction

toBundle

public Bundle toBundle ()

Adds this Icon to a Bundle that can be read back with the same parameters to createFromBundle(Bundle).

Returns
Bundle

toIcon

public Icon toIcon ()

This method is deprecated.
Use toIcon(Context) to generate the Icon object.

Returns
Icon

toIcon

public Icon toIcon (Context context)

Convert this compat object to Icon object.

Parameters
context Context

Returns
Icon Icon object

toString

public String toString ()

Returns
String