Java Code Examples for android.widget.ImageView#setImageTintList()

The following examples show how to use android.widget.ImageView#setImageTintList() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MainActivity.java    From MBEStyle with GNU General Public License v3.0 6 votes vote down vote up
private void setBottomIconOriColor(BottomNavigationView bottomView) {
    try {
        Field mMenuViewField = BottomNavigationView.class.getDeclaredField("mMenuView");
        mMenuViewField.setAccessible(true);
        BottomNavigationMenuView mMenuView = (BottomNavigationMenuView) mMenuViewField.get(bottomView);

        Field mButtonsField = BottomNavigationMenuView.class.getDeclaredField("mButtons");
        mButtonsField.setAccessible(true);
        BottomNavigationItemView[] mButtons = (BottomNavigationItemView[]) mButtonsField.get(mMenuView);

        Field mIconField = BottomNavigationItemView.class.getDeclaredField("mIcon");
        mIconField.setAccessible(true);

        for (BottomNavigationItemView item : mButtons) {
            ImageView mIcon = (ImageView) mIconField.get(item);
            mIcon.setImageTintList(null);
        }

    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 2
Source File: TitleBarView.java    From UIWidget with Apache License 2.0 6 votes vote down vote up
private void setImageTint(ImageView imageView, ColorStateList tint, PorterDuff.Mode
        tintMode) {
    if (imageView.getDrawable() == null) {
        return;
    }
    if (tint == null && tintMode == null) {
        return;
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        if (mActionTint != null) {
            imageView.setImageTintList(mActionTint);
        }
        if (mActionTintMode != null) {
            imageView.setImageTintMode(mActionTintMode);
        }
    } else {
        Drawable drawable = imageView.getDrawable();
        if (drawable != null && mActionTint != null) {
            drawable = drawable.mutate();
            drawable.setColorFilter(mActionTint.getDefaultColor(), mActionTintMode != null ? mActionTintMode : PorterDuff.Mode.SRC_ATOP);
        }
    }
}
 
Example 3
Source File: EmTintUtils.java    From AndroidTint with Apache License 2.0 6 votes vote down vote up
public static void setTint(@NonNull ImageView imageView, @ColorInt int color) {
    ColorStateList s1 = ColorStateList.valueOf(color);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        imageView.setImageTintList(s1);
    } else if (Build.VERSION.SDK_INT > Build.VERSION_CODES.GINGERBREAD_MR1) {
        Drawable drawable = DrawableCompat.wrap(imageView.getDrawable());
        imageView.setImageDrawable(drawable);
        DrawableCompat.setTintList(drawable, s1);
    } else {
        PorterDuff.Mode mode = PorterDuff.Mode.SRC_IN;
        if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1) {
            mode = PorterDuff.Mode.MULTIPLY;
        }
        if (imageView.getDrawable() != null)
            imageView.getDrawable().setColorFilter(color, mode);
    }
}
 
Example 4
Source File: BreadcrumbsView.java    From CommonUtils with Apache License 2.0 5 votes vote down vote up
@NonNull
private ImageView createArrow() {
    ImageView arrow = (ImageView) inflater.inflate(R.layout.breadcrumbs_arrow, this, false);
    arrow.setImageResource(arrowRes);
    arrow.setImageTintList(ColorStateList.valueOf(mColor));
    return arrow;
}
 
Example 5
Source File: MDTintUtil.java    From LLApp with Apache License 2.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static void setTint(@NonNull ImageView view, @ColorInt int color) {
    int[] colors = new int[]{color, color, color, color, color, color};
    int[][] states = new int[6][];
    states[0] = new int[]{android.R.attr.state_checked, android.R.attr.state_enabled};
    states[1] = new int[]{android.R.attr.state_enabled, android.R.attr.state_focused};
    states[2] = new int[]{android.R.attr.state_enabled};
    states[3] = new int[]{android.R.attr.state_focused};
    states[4] = new int[]{android.R.attr.state_window_focused};
    states[5] = new int[]{};
    view.setImageTintList(new ColorStateList(states, colors));
}
 
Example 6
Source File: ImageViewColorAdapter.java    From Scoops with Apache License 2.0 5 votes vote down vote up
@Override
public void applyColor(ImageView view, @ColorInt int color) {
    if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        view.setImageTintList(Utils.colorToStateList(color));
    }else{
        view.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
    }
}
 
Example 7
Source File: SUtils.java    From SublimePicker with Apache License 2.0 5 votes vote down vote up
public static void setImageTintList(ImageView imageView, ColorStateList colorStateList) {
    if (isApi_21_OrHigher()) {
        imageView.setImageTintList(colorStateList);
    } else {
        Drawable drawable = imageView.getDrawable();

        if (drawable != null) {
            Drawable wrapped = DrawableCompat.wrap(drawable);
            DrawableCompat.setTintList(wrapped, colorStateList);
            imageView.setImageDrawable(wrapped);
        }
    }
}
 
Example 8
Source File: CommonUtils.java    From CommonUtils with Apache License 2.0 4 votes vote down vote up
public static void setImageTintColor(@NonNull ImageView view, @ColorRes int res) {
    view.setImageTintList(ColorStateList.valueOf(ContextCompat.getColor(view.getContext(), res)));
}
 
Example 9
Source File: SwipeTodoView.java    From ticdesign with Apache License 2.0 4 votes vote down vote up
private void initView(Context context, AttributeSet attrs) {
    TypedArray typedArray = context.obtainStyledAttributes(attrs,
            R.styleable.SwipeTodoView);
    Drawable centerIconBg = typedArray.getDrawable(R.styleable.SwipeTodoView_tic_centerBtnBg);
    int leftIconResId = typedArray.getResourceId(R.styleable.SwipeTodoView_tic_leftBtnImage, 0);
    int rightIconResId = typedArray.getResourceId(R.styleable
            .SwipeTodoView_tic_rightBtnImage, 0);
    mShowLeftButton = (0 != leftIconResId);
    mShowRightButton = (0 != rightIconResId);
    int centerIconResId = typedArray.getResourceId(R.styleable
            .SwipeTodoView_tic_centerBtnImage, 0);
    ColorStateList defaultColorList = ColorStateList.valueOf(Color.BLUE);
    ColorStateList leftColorStateList = typedArray.getColorStateList(R.styleable
            .SwipeTodoView_tic_leftBtnColor);
    if (null == leftColorStateList) {
        leftColorStateList = defaultColorList;
    }
    ColorStateList rightColorStateList = typedArray.getColorStateList(R.styleable
            .SwipeTodoView_tic_rightBtnColor);
    if (null == rightColorStateList) {
        rightColorStateList = defaultColorList;
    }
    ColorStateList leftBgColor = typedArray.getColorStateList(R.styleable
            .SwipeTodoView_tic_leftBtnBgColor);
    ColorStateList rightBgColor = typedArray.getColorStateList(R.styleable
            .SwipeTodoView_tic_rightBtnBgColor);
    mLeftBgDrawable = new ArcDrawable(Color.WHITE);
    mLeftBgDrawable.setTintList(leftBgColor);
    mLeftBgDrawable.setGravity(Gravity.LEFT);
    mLeftBgDrawable.setAlpha(0);
    mRightBgDrawable = new ArcDrawable(Color.WHITE);
    mRightBgDrawable.setGravity(Gravity.RIGHT);
    mRightBgDrawable.setTintList(rightBgColor);
    mRightBgDrawable.setAlpha(0);
    String content = typedArray.getString(R.styleable.SwipeTodoView_tic_content);
    String subContent = typedArray.getString(R.styleable.SwipeTodoView_tic_subContent);
    typedArray.recycle();

    mOuterCircleIv = (ImageView) findViewById(R.id.outer_circle_iv);
    mMiddleCircleIv = (ImageView) findViewById(R.id.middle_circle_iv);
    mInnerCircleIv = (ImageView) findViewById(R.id.inner_circle_iv);
    mContentTv = (TextView) findViewById(R.id.content_tv);
    mSubContentTv = (TextView) findViewById(R.id.sub_content_tv);
    mTipTv = (TextView) findViewById(R.id.tip_tv);
    mCenterIv = (ImageView) findViewById(R.id.center_iv);
    mLeftIv = (ImageView) findViewById(R.id.left_iv);
    mRightIv = (ImageView) findViewById(R.id.right_iv);

    mContentTv.setText(content);
    mSubContentTv.setText(subContent);
    mCenterIv.setBackground(centerIconBg);
    if (centerIconResId != 0) {
        mHasCenterIcon = true;
        mCenterIv.setImageResource(centerIconResId);
        mCenterIv.getDrawable().setAlpha(255);
    }
    mLeftIv.setImageResource(leftIconResId);
    mLeftIv.setImageTintList(leftColorStateList);
    mLeftIv.setBackground(mLeftBgDrawable);
    mRightIv.setImageResource(rightIconResId);
    mRightIv.setImageTintList(rightColorStateList);
    mRightIv.setBackground(mRightBgDrawable);
}
 
Example 10
Source File: LollipopUtils.java    From LyricHere with Apache License 2.0 4 votes vote down vote up
public static void setImageTintList(ImageView imageView, ColorStateList colorStateList) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        imageView.setImageTintList(colorStateList);
    }
}
 
Example 11
Source File: FlipperUserAdapter.java    From NGA-CLIENT-VER-OPEN-SOURCE with GNU General Public License v2.0 4 votes vote down vote up
private void handleUserAvatar(ImageView avatarIV, String url) {
    avatarIV.setImageTintList(null);
    ImageUtils.loadRoundCornerAvatar(avatarIV, url);
}