Example usage for android.graphics.drawable Drawable setAlpha

List of usage examples for android.graphics.drawable Drawable setAlpha

Introduction

In this page you can find the example usage for android.graphics.drawable Drawable setAlpha.

Prototype

public abstract void setAlpha(@IntRange(from = 0, to = 255) int alpha);

Source Link

Document

Specify an alpha value for the drawable.

Usage

From source file:Main.java

public static Drawable setAlpha(Drawable draw, int alpha) {
    draw.setAlpha(alpha);
    draw.invalidateSelf();//from w  w  w . j  av a  2  s  .  co  m
    return draw;
}

From source file:Main.java

public static void setBackgroundPreservingAlpha(View view, Drawable drawable) {
    if (view.getBackground() != null) {
        drawable.setAlpha(view.getBackground().getAlpha());
    }/*from www.  j a  v a  2  s .  c o  m*/
    view.setBackground(drawable);
}

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);/*from  ww w .  j  a va  2 s . c  om*/
    } else {
        Drawable drawable = view.getBackground();
        if (drawable != null) {
            drawable.setAlpha(alpha);
        }
    }
}

From source file:Main.java

/**
 * Android doesn't fade out disabled menu item icons, so do it ourselves
 *///  ww w  .j  a v  a2  s  .c om
public static void fixupMenuAlpha(Menu menu) {
    for (int i = 0; i < menu.size(); i++) {
        MenuItem item = menu.getItem(i);
        Drawable icon = item.getIcon();
        if (icon != null) {
            icon.setAlpha(item.isEnabled() ? 255 : 64);
        }
    }
}

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 w  w  w  .  j  a  va  2  s  .  c o m*/
    } else {
        Drawable drawable = view.getBackground();
        if (drawable != null) {
            drawable.setAlpha((int) (alpha * 255));
        }
    }
}

From source file:Main.java

public static void overrideColorWithTransparency(int i, Drawable drawable, int j) {
    drawable.setColorFilter(i, android.graphics.PorterDuff.Mode.MULTIPLY);
    if (android.os.Build.VERSION.SDK_INT >= 11) {
        drawable.setAlpha(j);
    }//  w  ww  . j av  a 2  s  .  c  om
}

From source file:com.gc.markdown.utils.ViewUtils.java

/**
 * Set view alpha/*from www  .  java2s  .  co  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

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@NonNull/*from  w w  w  .j  av a  2 s.c  om*/
private static Drawable getPressedColorRippleDrawable(int normalColor, int pressedColor) {
    Drawable drawable = new RippleDrawable(getPressedColorSelector(normalColor, pressedColor),
            getColorDrawableFromColor(normalColor), null);
    drawable.setAlpha(70);
    return drawable;
}

From source file:jahirfiquitiva.iconshowcase.utilities.color.ToolbarColorizer.java

public static void hideSearchHintIcon(Context context, SearchView searchView) {
    if (context != null) {
        final Class<?> searchViewClass = searchView.getClass();
        try {// w w  w .java  2s. c  o m
            final Field mSearchHintIcon = searchViewClass.getDeclaredField("mSearchHintIcon");
            mSearchHintIcon.setAccessible(true);
            Drawable mSearchHintIconDrawable = (Drawable) mSearchHintIcon.get(searchView);
            mSearchHintIconDrawable.setBounds(0, 0, 0, 0);
            mSearchHintIconDrawable.setAlpha(0);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

From source file:com.android.clear.reminder.AnimatorUtils.java

/**
 * Sets the alpha of the top layer's drawable (of the background) only, if the background is a
 * layer drawable, to ensure that the other layers (i.e., the selectable item background, and
 * therefore the touch feedback RippleDrawable) are not affected.
 *
 * @param view the affected view/*from   ww w  .  j ava 2s. co  m*/
 * @param value the alpha value (0-255)
 */
public static void setBackgroundAlpha(View view, Integer value) {
    Drawable background = view.getBackground();
    if (background instanceof LayerDrawable && ((LayerDrawable) background).getNumberOfLayers() > 0) {
        background = ((LayerDrawable) background).getDrawable(0);
    }
    background.setAlpha(value);
}