Example usage for android.view View getBackground

List of usage examples for android.view View getBackground

Introduction

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

Prototype

public Drawable getBackground() 

Source Link

Document

Gets the background drawable

Usage

From source file:Main.java

public static void setAlpha(View view, int alpha) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        view.setAlpha(alpha / 255.0f);/*  w w  w.j ava  2s  . com*/
    } else {
        Drawable drawable = view.getBackground();
        if (drawable != null) {
            drawable.setAlpha(alpha);
        }
    }
}

From source file:com.ruesga.rview.misc.BindingAdapters.java

@BindingAdapter("bindBackgroundTint")
public static void bindBackgroundTint(View v, int color) {
    final Drawable dw = v.getBackground();
    DrawableCompat.setTint(dw, color);//from   ww w. j a  v a 2s. co m
    v.setBackground(dw);
}

From source file:Main.java

public static void setAlpha(View view, float alpha) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        view.setAlpha(alpha);/*from www  .  j  a v  a  2 s . co m*/
    } else {
        Drawable drawable = view.getBackground();
        if (drawable != null) {
            drawable.setAlpha((int) (alpha * 255));
        }
    }
}

From source file:Main.java

private static void upEffect(View v) {
    //if(v.getBackground() == null) return;

    Drawable drwb;//from w  w  w.  j  ava 2 s  . co m
    if (v instanceof ImageView) {
        drwb = ((ImageView) v).getDrawable();

    } else {
        drwb = v.getBackground();
    }

    if (drwb == null)
        return;

    drwb.clearColorFilter();
    v.invalidate();
}

From source file:Main.java

public static Bitmap getBitmapFromView(View view) {
    Bitmap returnedBitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(returnedBitmap);
    Drawable bgDrawable = view.getBackground();
    if (bgDrawable != null)
        bgDrawable.draw(canvas);//from   w  w  w  .  j a  v  a  2  s. c  o m
    else
        canvas.drawColor(Color.WHITE);
    view.draw(canvas);
    return returnedBitmap;
}

From source file:Main.java

public static Bitmap view2Bitmap(View view) {
    if (view == null)
        return null;
    Bitmap ret = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(ret);
    Drawable bgDrawable = view.getBackground();
    if (bgDrawable != null) {
        bgDrawable.draw(canvas);//  w w  w.ja  va 2  s  .  co  m
    } else {
        canvas.drawColor(Color.WHITE);
    }
    view.draw(canvas);
    return ret;
}

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.gc.markdown.utils.ViewUtils.java

/**
 * Set view alpha//  www  . j  a  v  a 2 s.c o m
 * ?
 *
 * @param view  view
 * @param alpha alpha value
 */
public static void setAlpha(View view, float alpha) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        view.setAlpha(alpha);
    } else {
        Drawable drawable = view.getBackground();
        if (drawable != null) {
            drawable.setAlpha((int) (alpha * 255));
        }
    }
}

From source file:Main.java

/**
 * Blur the view's background, for the original idea please refer to:
 * http://www.cnblogs.com/lipeil/p/3997992.html
 * @param context//from  www  .j a va2 s .c om
 * @param view
 */
public static void blur(Context context, View view) {
    Bitmap bitmap = ((BitmapDrawable) view.getBackground()).getBitmap();
    bitmap = blur(context, bitmap);
    view.setBackground(new BitmapDrawable(bitmap));
}

From source file:org.michaelevans.etsyblur.utils.Utils.java

public static Bitmap drawViewToBitmap(View view, int color) {
    Bitmap returnedBitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(returnedBitmap);
    Drawable bgDrawable = view.getBackground();
    if (bgDrawable != null)
        bgDrawable.draw(canvas);/*  www . j a  va 2  s  .  com*/
    else
        canvas.drawColor(color);
    view.draw(canvas);
    return returnedBitmap;
}