Example usage for android.view View setBackgroundDrawable

List of usage examples for android.view View setBackgroundDrawable

Introduction

In this page you can find the example usage for android.view View setBackgroundDrawable.

Prototype

@Deprecated
public void setBackgroundDrawable(Drawable background) 

Source Link

Usage

From source file:Main.java

@SuppressWarnings("deprecation")
public static void setImageBackground(View view, int width, int height, int ResId, Activity context) {
    Options opts = new Options();
    opts.outHeight = height;/*from w  ww  .  j a v a 2 s.c  om*/
    opts.outWidth = width;
    opts.inJustDecodeBounds = false;
    Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), ResId, opts);
    view.setBackgroundDrawable(new BitmapDrawable(bitmap));
}

From source file:com.bilibili.socialize.share.utils.selector.BaseSharePlatformSelector.java

protected static GridView createShareGridView(final Context context,
        AdapterView.OnItemClickListener onItemClickListener) {
    GridView grid = new GridView(context);
    ListAdapter adapter = new ArrayAdapter<ShareTarget>(context, 0, shareTargets) {
        // no need scroll
        @Override/*from  w ww  .  j  a  v  a  2s.com*/
        public View getView(int position, View convertView, ViewGroup parent) {
            View view = LayoutInflater.from(parent.getContext())
                    .inflate(R.layout.bili_socialize_shareboard_item, parent, false);
            view.setBackgroundDrawable(null);
            ImageView image = (ImageView) view.findViewById(R.id.bili_socialize_shareboard_image);
            TextView platform = (TextView) view.findViewById(R.id.bili_socialize_shareboard_pltform_name);

            ShareTarget target = getItem(position);
            image.setImageResource(target.iconId);
            platform.setText(target.titleId);
            return view;
        }
    };
    grid.setNumColumns(-1);
    grid.setStretchMode(GridView.STRETCH_COLUMN_WIDTH);
    grid.setColumnWidth(context.getResources().getDimensionPixelSize(R.dimen.bili_socialize_shareboard_size));
    grid.setLayoutParams(new ViewGroup.LayoutParams(-1, -2));
    grid.setSelector(R.drawable.bili_socialize_selector_item_background);
    grid.setAdapter(adapter);
    grid.setOnItemClickListener(onItemClickListener);
    return grid;
}

From source file:Main.java

/**
 * Hack to fix pre JB MR1 Kudos to @cyrilmottier
 *
 * @param view     view drawable attached too.
 * @param drawable drawable which gets invalidated
 *//*from  ww w. jav  a 2  s . c o m*/
static void fixParallaxBackgroundPreJBMR1(final View view, final Drawable drawable) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
        drawable.setCallback(new Drawable.Callback() {
            @Override
            public void invalidateDrawable(Drawable who) {
                view.setBackgroundDrawable(who);
            }

            @Override
            public void scheduleDrawable(Drawable who, Runnable what, long when) {
            }

            @Override
            public void unscheduleDrawable(Drawable who, Runnable what) {
            }
        });
    }
}

From source file:com.doomy.library.Internal.Compat.SeekBarCompat.java

/**
 * android.support.v4.view.ViewCompat SHOULD include this once and for all!!
 * But it doesn't.../*  w w  w.  j ava 2  s.  c om*/
 *
 * @param view
 * @param background
 */
@SuppressWarnings("deprecation")
public static void setBackground(View view, Drawable background) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        SeekBarCompatDontCrash.setBackground(view, background);
    } else {
        view.setBackgroundDrawable(background);
    }
}

From source file:Main.java

@SuppressWarnings("deprecation")
public static void setBackGround(View view, Drawable drawable) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
        view.setBackgroundDrawable(drawable);
    } else {/*  w  ww .  ja  v a  2  s  .c o m*/
        view.setBackground(drawable);
    }
}

From source file:Main.java

public static void unbindDrawables(View view) {
    if (null == view) {
        return;/*  w w  w .j  ava  2  s .  c o m*/
    }
    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();
        }
    }
}

From source file:Main.java

/**
 * release all image resource bind on view
 * @param view// w  w  w . j a v  a  2s.  c o m
 */
@SuppressWarnings("deprecation")
public static void unbindDrawables(View view) {
    if (null == view) {
        return;
    }
    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();
        }
    }
}

From source file:io.mpos.ui.shared.util.UiHelper.java

public static void tintView(View view, int color) {
    Drawable wrappedDrawable = DrawableCompat.wrap(view.getBackground());
    DrawableCompat.setTint(wrappedDrawable, color);
    view.setBackgroundDrawable(wrappedDrawable);
}

From source file:com.activiti.android.ui.utils.UIUtils.java

/**
 * Set the background view with the drawable associated.
 *
 * @param v/*from w w w. ja v  a 2  s  .  c o  m*/
 * @param background
 */
@SuppressWarnings("deprecation")
public static void setBackground(View v, Drawable background) {
    if (AndroidVersion.isJBOrAbove()) {
        v.setBackground(background);
    } else {
        v.setBackgroundDrawable(background);
    }
}

From source file:despotoski.nikola.github.com.bottomnavigationlayout.Util.java

public static void setBackground(View view, @NonNull Drawable drawable) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        view.setBackground(drawable);//from  www  .  j a  va  2 s  .co  m
    } else {
        //noinspection deprecation
        view.setBackgroundDrawable(drawable);
    }
}