Example usage for android.graphics.drawable Drawable setColorFilter

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

Introduction

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

Prototype

public void setColorFilter(@ColorInt int color, @NonNull PorterDuff.Mode mode) 

Source Link

Document

Specify a color and Porter-Duff mode to be the color filter for this drawable.

Usage

From source file:com.douncoding.noe.ui.car_action.register.CarRegisterFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.menu_register, menu);
    // DONE  ? //  w w  w  . ja va2 s  . c  om
    Drawable icon = menu.getItem(0).getIcon();
    icon.setColorFilter(ContextCompat.getColor(getContext(), R.color.carPrimaryColor), PorterDuff.Mode.SRC_IN);
    super.onCreateOptionsMenu(menu, inflater);
}

From source file:de.vanita5.twittnuker.util.ThemeUtils.java

private static Drawable applyActionBarDrawable(final Context context, final Drawable d,
        final boolean applyAlpha) {
    if (d == null)
        return null;
    d.mutate();// ww  w  . j  a  v  a 2s  .c o m
    if (d instanceof LayerDrawable) {
        final Drawable colorLayer = ((LayerDrawable) d).findDrawableByLayerId(R.id.color_layer);
        if (colorLayer != null) {
            final int color = getActionBarColor(context);
            colorLayer.setColorFilter(color, PorterDuff.Mode.MULTIPLY);
        }
    }
    if (applyAlpha) {
        d.setAlpha(getThemeAlpha(context));
    }
    return d;
}

From source file:io.mattcarroll.hover.defaulthovermenu.toolbar.ToolbarNavigatorContent.java

private Drawable createBackArrowDrawable() {
    // Load the desired back-arrow color from the theme that we're using.
    int[] attrIds = new int[] { R.attr.colorControlNormal };
    TypedArray attrs = getContext().obtainStyledAttributes(attrIds);
    int backArrowColor = attrs.getColor(attrs.getIndex(0), 0xFF000000);
    attrs.recycle();//from  www.ja va2 s .co m

    // Apply the desired color to the back-arrow icon and return it.
    Drawable backArrowDrawable = ContextCompat.getDrawable(getContext(), R.drawable.ic_arrow_back);
    backArrowDrawable.setColorFilter(backArrowColor, PorterDuff.Mode.SRC_ATOP);
    return backArrowDrawable;
}

From source file:com.applivery.applvsdklib.ui.views.update.MustUpdateViewImpl.java

private void initViewElements(View view) {
    this.updateMessage = (TextView) view.findViewById(R.id.must_update_message);
    this.permissionsDenied = (TextView) view.findViewById(R.id.permissions_denied_message);
    this.update = (Button) view.findViewById(R.id.must_update_button);
    this.progressBar = (ProgressBar) view.findViewById(R.id.must_update_progress_bar);

    LayerDrawable layerDrawable = (LayerDrawable) progressBar.getProgressDrawable();
    Drawable progressDrawable = layerDrawable.findDrawableByLayerId(android.R.id.progress);
    progressDrawable.setColorFilter(
            ContextCompat.getColor(AppliverySdk.getApplicationContext(), R.color.appliveryMainColor),
            PorterDuff.Mode.SRC_IN);//from   w w  w. ja v a2 s .  co  m
}

From source file:com.facebook.getrecommendations.MainActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.main_activity_actions, menu);
    MenuItem menuItem = menu.findItem(R.id.menu_overflow);
    Drawable drawable = getResources().getDrawable(R.drawable.fbui_3_dots_v_l);
    int color = getResources().getColor(R.color.getrecommendations_primary_light);
    drawable.setColorFilter(color, PorterDuff.Mode.SRC_IN);
    menuItem.setIcon(drawable);//from  w  w  w.  j  a  va2s  .  co m
    return super.onCreateOptionsMenu(menu);
}

From source file:org.mariotaku.twidere.util.ThemeUtils.java

public static void setActionBarOverflowColor(ActionMenuView actionMenuView, int itemColor) {
    if (actionMenuView == null)
        return;/*from ww w  . ja  v  a2  s. c  om*/
    View overflowView = null;
    for (int i = 0, j = actionMenuView.getChildCount(); i < j; i++) {
        final View child = actionMenuView.getChildAt(i);
        final ActionMenuView.LayoutParams lp = (ActionMenuView.LayoutParams) child.getLayoutParams();
        if (lp.isOverflowButton) {
            overflowView = child;
            break;
        }
    }
    if (!(overflowView instanceof ImageView))
        return;
    final Drawable drawable = ((ImageView) overflowView).getDrawable();
    if (drawable == null)
        return;
    drawable.setColorFilter(itemColor, Mode.SRC_ATOP);
}

From source file:com.philliphsu.bottomsheetpickers.Utils.java

/**
 * Sets the color on the {@code view}'s {@code selectableItemBackground} or the
 * borderless variant, whichever was set as the background.
 * @param view the view that should have its highlight color changed
 *//*from w  w  w .j a va2  s . c om*/
public static void setColorControlHighlight(@NonNull View view, @ColorInt int color) {
    Drawable selectableItemBackground = view.getBackground();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP
            && selectableItemBackground instanceof RippleDrawable) {
        ((RippleDrawable) selectableItemBackground).setColor(ColorStateList.valueOf(color));
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && Utils.isTv(view.getContext())) {
            ((RippleDrawable) selectableItemBackground).setRadius(72);
        }
    } else {
        // Draws the color (src) onto the background (dest) *in the same plane*.
        // That means the color is not overlapping (i.e. on a higher z-plane, covering)
        // the background. That would be done with SRC_OVER.
        // The DrawableCompat tinting APIs *could* be a viable alternative, if you
        // call setTintMode(). Previous attempts using those APIs failed without
        // the tint mode. However, those APIs have the overhead of mutating and wrapping
        // the drawable.
        selectableItemBackground.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
    }
}

From source file:org.oucho.whois.MainActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {

    Context context = getApplicationContext();

    getMenuInflater().inflate(R.menu.menu_main, menu);

    Drawable drawable = menu.findItem(R.id.about).getIcon();
    drawable.mutate();/*  w  w  w .j av  a2s  . c om*/
    drawable.setColorFilter(ContextCompat.getColor(context, R.color.colorPrimaryDark),
            PorterDuff.Mode.SRC_ATOP);
    return true;
}

From source file:com.forrestguice.suntimeswidget.SuntimesUtils.java

public static ImageSpan createImageSpan(Context context, int drawableID, int width, int height, int tint) {
    Drawable drawable = null;
    try {/*from w  w  w . j  a  v  a2 s . co m*/
        drawable = context.getResources().getDrawable(drawableID);
    } catch (Exception e) {
        Log.e("createImageSpan", "invalid drawableID " + drawableID + "! ...set to null.");
    }

    if (drawable != null) {
        if (width > 0 && height > 0) {
            drawable.setBounds(0, 0, width, height);
        }
        drawable.setColorFilter(tint, PorterDuff.Mode.SRC_ATOP);
    }
    return new ImageSpan(drawable);
}

From source file:io.lqd.sdk.visual.SlideUp.java

public void setUpButton() {
    final ImageView mArrowButton = (ImageView) container.findViewById(R.id.slideUpArrowButton);

    for (final LQInAppMessage.Cta cta : mSlideModel.getCtas()) {

        Drawable myArrow = ContextCompat.getDrawable(mContext, R.drawable.arrow);

        // Change arrow button color
        myArrow.setColorFilter(Color.parseColor(cta.getButtonColor()), PorterDuff.Mode.SRC_IN);
        ((ImageView) container.findViewById(R.id.slideUpArrowButton)).setImageDrawable(myArrow);

        mArrowButton.setOnClickListener(new View.OnClickListener() {
            @Override//  w  ww .jav  a 2s .co  m
            public void onClick(View v) {
                Intent mIntent = new Intent(Intent.ACTION_VIEW);
                if (cta.getDeepLink() != null) {
                    try {
                        mIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                        mIntent.setData(Uri.parse(cta.getDeepLink()));
                        Liquid.getInstance().trackCta(cta);
                        mContext.startActivity(mIntent);
                    } catch (Exception e) {
                        LQLog.infoVerbose("Canceled or not properly assigned to deeplink or URL");
                    }
                }
                mPopupWindow.dismiss();
            }
        });
    }
}