Skip to content

Most visited

Recently visited

navigation

AppCompatImageView

public class AppCompatImageView
extends ImageView implements TintableBackgroundView

java.lang.Object
   ↳ android.view.View
     ↳ android.widget.ImageView
       ↳ android.support.v7.widget.AppCompatImageView


A ImageView which supports compatible features on older version of the platform, including:

This will automatically be used when you use ImageView in your layouts. You should only need to manually use this class when writing custom views.

Summary

XML attributes

android.support.v7.appcompat:srcCompat Sets a drawable as the content of this ImageView. 

Inherited XML attributes

From class android.widget.ImageView
From class android.view.View

Inherited constants

From class android.view.View

Inherited fields

From class android.view.View

Public constructors

AppCompatImageView(Context context)
AppCompatImageView(Context context, AttributeSet attrs)
AppCompatImageView(Context context, AttributeSet attrs, int defStyleAttr)

Public methods

boolean hasOverlappingRendering()

Returns whether this View has content which overlaps.

void setBackgroundDrawable(Drawable background)

This method is deprecated. use setBackground(Drawable) instead

void setBackgroundResource(int resId)

Set the background to a given resource.

void setImageBitmap(Bitmap bm)

Sets a Bitmap as the content of this ImageView.

void setImageDrawable(Drawable drawable)

Sets a drawable as the content of this ImageView.

void setImageIcon(Icon icon)

Sets the content of this ImageView to the specified Icon.

void setImageResource(int resId)

Sets a drawable as the content of this ImageView.

void setImageURI(Uri uri)

Sets the content of this ImageView to the specified Uri.

Protected methods

void drawableStateChanged()

This function is called whenever the state of the view changes in such a way that it impacts the state of drawables being shown.

Inherited methods

From class android.widget.ImageView
From class android.view.View
From class java.lang.Object
From interface android.graphics.drawable.Drawable.Callback
From interface android.view.KeyEvent.Callback
From interface android.view.accessibility.AccessibilityEventSource
From interface android.support.v4.view.TintableBackgroundView

XML attributes

android.support.v7.appcompat:srcCompat

Sets a drawable as the content of this ImageView. Allows the use of vector drawable when running on older versions of the platform.

May be a reference to another resource, in the form "@[+][package:]type/name" or a theme attribute in the form "?[package:]type/name".

Related methods:

Public constructors

AppCompatImageView

added in version 24.2.0
AppCompatImageView (Context context)

Parameters
context Context

AppCompatImageView

added in version 24.2.0
AppCompatImageView (Context context, 
                AttributeSet attrs)

Parameters
context Context
attrs AttributeSet

AppCompatImageView

added in version 24.2.0
AppCompatImageView (Context context, 
                AttributeSet attrs, 
                int defStyleAttr)

Parameters
context Context
attrs AttributeSet
defStyleAttr int

Public methods

hasOverlappingRendering

boolean hasOverlappingRendering ()

Returns whether this View has content which overlaps.

This function, intended to be overridden by specific View types, is an optimization when alpha is set on a view. If rendering overlaps in a view with alpha < 1, that view is drawn to an offscreen buffer and then composited into place, which can be expensive. If the view has no overlapping rendering, the view can draw each primitive with the appropriate alpha value directly. An example of overlapping rendering is a TextView with a background image, such as a Button. An example of non-overlapping rendering is a TextView with no background, or an ImageView with only the foreground image. The default implementation returns true; subclasses should override if they have cases which can be optimized.

The current implementation of the saveLayer and saveLayerAlpha methods in Canvas necessitates that a View return true if it uses the methods internally without passing the CLIP_TO_LAYER_SAVE_FLAG.

Note: The return value of this method is ignored if forceHasOverlappingRendering(boolean) has been called on this view.

Returns
boolean true if the content in this view might overlap, false otherwise.

setBackgroundDrawable

void setBackgroundDrawable (Drawable background)

This method is deprecated.
use setBackground(Drawable) instead

Parameters
background Drawable

setBackgroundResource

void setBackgroundResource (int resId)

Set the background to a given resource. The resource should refer to a Drawable object or 0 to remove the background.

Parameters
resId int: The identifier of the resource.

setImageBitmap

void setImageBitmap (Bitmap bm)

Sets a Bitmap as the content of this ImageView.

Parameters
bm Bitmap: The bitmap to set

setImageDrawable

void setImageDrawable (Drawable drawable)

Sets a drawable as the content of this ImageView.

Parameters
drawable Drawable: the Drawable to set, or null to clear the content

setImageIcon

void setImageIcon (Icon icon)

Sets the content of this ImageView to the specified Icon.

Depending on the Icon type, this may do Bitmap reading and decoding on the UI thread, which can cause UI jank. If that's a concern, consider using loadDrawableAsync(Context, Icon.OnDrawableLoadedListener, Handler) and then setImageDrawable(android.graphics.drawable.Drawable) instead.

Parameters
icon Icon: an Icon holding the desired image, or null to clear the content

setImageResource

void setImageResource (int resId)

Sets a drawable as the content of this ImageView.

Allows the use of vector drawables when running on older versions of the platform.

Related XML Attributes:

Parameters
resId int: the resource identifier of the drawable

See also:

setImageURI

void setImageURI (Uri uri)

Sets the content of this ImageView to the specified Uri.

This does Bitmap reading and decoding on the UI thread, which can cause a latency hiccup. If that's a concern, consider using setImageDrawable(Drawable) or setImageBitmap(android.graphics.Bitmap) and BitmapFactory instead.

On devices running SDK < 24, this method will fail to apply correct density scaling to images loaded from content and file schemes. Applications running on devices with SDK >= 24 MUST specify the targetSdkVersion in their manifest as 24 or above for density scaling to be applied to images loaded from these schemes.

Parameters
uri Uri: the Uri of an image, or null to clear the content

Protected methods

drawableStateChanged

void drawableStateChanged ()

This function is called whenever the state of the view changes in such a way that it impacts the state of drawables being shown.

If the View has a StateListAnimator, it will also be called to run necessary state change animations.

Be sure to call through to the superclass when overriding this function.

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.

Take a one-minute survey?
Help us improve Android tools and documentation.