Example usage for android.widget ImageView setImageDrawable

List of usage examples for android.widget ImageView setImageDrawable

Introduction

In this page you can find the example usage for android.widget ImageView setImageDrawable.

Prototype

public void setImageDrawable(@Nullable Drawable drawable) 

Source Link

Document

Sets a drawable as the content of this ImageView.

Usage

From source file:Main.java

@SuppressWarnings("deprecation")
private static void setDrawableToImageViewBeforeLollipop(ImageView imageView, int drawableId) {
    imageView.setImageDrawable(imageView.getContext().getResources().getDrawable(drawableId));
}

From source file:Main.java

/**
 * Sets the image for an ImageView./*from   www  . java  2 s  .  co m*/
 */
public static void setImage(ImageView view, Drawable drawable) {
    view.setImageDrawable(drawable);
    if (drawable != null) {
        view.setAdjustViewBounds(true);
    }
    view.requestLayout();
}

From source file:Main.java

@SuppressWarnings("deprecation")
private static void cleanView(View view) {
    try {/*from w  ww.ja  v a2s. c om*/
        view.setBackgroundDrawable(null);
    } catch (Exception e) {
    }

    if (view instanceof ImageView)
        try {
            ImageView imageView = (ImageView) view;
            imageView.setImageDrawable(null);
        } catch (Exception e) {
        }
}

From source file:Main.java

public static void setDrawable(ImageView imageView, Drawable drawable) {
    if (imageView != null && drawable != null) {
        imageView.setImageDrawable(drawable);
    }//from   www  .  j  a  v a  2 s  .  co m
}

From source file:Main.java

public static void inflateImageViewWithDrawableId(Context ctx, ImageView iv, int id) {
    if (iv == null)
        throw new IllegalArgumentException();
    iv.setImageDrawable(getDrawable(ctx, id));
}

From source file:Main.java

public static void setIconColor(ImageView icon, int color) {
    Drawable iconDrawable = icon.getDrawable();
    icon.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_ATOP));
    icon.setImageDrawable(iconDrawable);
}

From source file:Main.java

public static void unbindImageDrawables(View view) {
    if (null == view) {
        return;/*from  w  w w.ja  va 2  s .c om*/
    }

    if (view instanceof ImageView) {
        ImageView imageView = (ImageView) view;

        if (imageView.getDrawable() != null) {
            imageView.getDrawable().setCallback(null);
            imageView.setImageDrawable(null);
        }
    }
    if (view instanceof ViewGroup) {
        for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++) {
            unbindImageDrawables(((ViewGroup) view).getChildAt(i));
        }
    }
}

From source file:Main.java

public static void applySampledResourceToImageView(Resources res, int resId, int reqWidth, int reqHeight,
        ImageView imageView) {
    if (resId != 0) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            imageView.setImageDrawable(res.getDrawable(resId));
        } else {// w w w  . j a v  a  2 s  .  c  o m
            // workaround for old versions of android
            imageView.setImageBitmap(decodeSampledBitmapFromResource(res, resId, reqWidth, reqHeight));
        }
    }
}

From source file:Main.java

/**
 * launcher specific title/*from   w  w  w .  j  a va2s  . c  o m*/
 * @param a
 * @param iv
 * @return
 */
public static boolean checkAndSetLauncherTitle(ImageView iv) {
    if (iv == null)
        return false;
    Drawable d = Drawable.createFromPath(CUST_PATH + LAUNCHER_LOGO_FILE_NAME);
    if (d != null) {
        iv.setImageDrawable(d);
        return true;
    } else
        return false;
}

From source file:Main.java

public static void unbindDrawables(View view) {
    if (null == view) {
        return;//from w  ww .j  a  v a 2s .  com
    }
    if (view.getBackground() != null) {
        view.getBackground().setCallback(null);
        if (Build.VERSION.SDK_INT >= 16)
            view.setBackground(null);
        else
            view.setBackgroundDrawable(null);
    }
    if (view instanceof ImageView) {
        ImageView imageView = (ImageView) view;

        if (imageView.getDrawable() != null) {
            imageView.getDrawable().setCallback(null);
            imageView.setImageDrawable(null);
        }
    }
    if (view instanceof ViewGroup) {
        for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++) {
            unbindDrawables(((ViewGroup) view).getChildAt(i));
        }
        if (!(view instanceof AdapterView<?>)) {
            ((ViewGroup) view).removeAllViews();
        }
    }
}