Skip to content

Most visited

Recently visited

navigation

AppCompatImageButton

public class AppCompatImageButton
extends ImageButton implements TintableBackgroundView

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


A ImageButton which supports compatible features on older versions of the platform, including:

This will automatically be used when you use ImageButton in your layouts and the top-level activity / dialog is provided by appcompat. You should only need to manually use this class when writing custom views.

Summary

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

AppCompatImageButton(Context context)
AppCompatImageButton(Context context, AttributeSet attrs)
AppCompatImageButton(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.ImageButton
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

Public constructors

AppCompatImageButton

added in version 24.2.0
AppCompatImageButton (Context context)

Parameters
context Context

AppCompatImageButton

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

Parameters
context Context

attrs AttributeSet

AppCompatImageButton

added in version 24.2.0
AppCompatImageButton (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

added in version 26.0.0
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.

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

Parameters
resId int: the resource identifier of the drawable

setImageURI

void setImageURI (Uri uri)

Sets the content of this ImageView to the specified Uri. Note that you use this method to load images from a local Uri only.

To learn how to display images from a remote Uri see: Handling Bitmaps

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.

Get the latest Android developer news and tips that will help you find success on Google Play.

* Required Fields

Hooray!

Browse this site in ?

You requested a page in , but your language preference for this site is .

Would you like to change your language preference and browse this site in ? If you want to change your language preference later, use the language menu at the bottom of each page.

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 short survey?
Help us improve the Android developer experience.
(Sep 2017 survey)