cleanup View With Image - Android User Interface

Android examples for User Interface:View Bitmap

Description

cleanup View With Image

Demo Code


//package com.java2s;

import android.annotation.SuppressLint;

import android.graphics.drawable.Drawable;
import android.os.Build;

import android.view.View;

import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.SeekBar;

public class Main {

    public static View cleanupViewWithImage(View view) {
        if (view instanceof ImageButton) {
            ImageButton ib = (ImageButton) view;
            ib.setImageDrawable(null);/*  w  ww  .  j a  va2  s  .co m*/
        } else if (view instanceof ImageView) {
            ImageView iv = (ImageView) view;
            iv.setImageDrawable(null);
        } else if (view instanceof SeekBar) {
            SeekBar sb = (SeekBar) view;
            sb.setProgressDrawable(null);
            sb.setThumb(null);
        }
        return setBackgroundDrawable(view, null);
    }

    @SuppressWarnings({ "deprecation", "javadoc" })
    @SuppressLint("NewApi")
    public static View setBackgroundDrawable(View view, Drawable drawable) {
        if (drawable == null) {
            view.setBackgroundResource(0);
            return view;
        }
        if (Build.VERSION.SDK_INT >= 16) {
            view.setBackground(drawable);
        } else {
            view.setBackgroundDrawable(drawable);
        }
        return view;
    }
}

Related Tutorials