android.widget.ImageView#setImageTintList ( )源码实例Demo

下面列出了android.widget.ImageView#setImageTintList ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: MBEStyle   文件: MainActivity.java
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();
    }
}
 
源代码2 项目: UIWidget   文件: TitleBarView.java
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);
        }
    }
}
 
源代码3 项目: AndroidTint   文件: EmTintUtils.java
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);
    }
}
 
源代码4 项目: CommonUtils   文件: BreadcrumbsView.java
@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;
}
 
源代码5 项目: LLApp   文件: MDTintUtil.java
@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));
}
 
源代码6 项目: Scoops   文件: ImageViewColorAdapter.java
@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);
    }
}
 
源代码7 项目: SublimePicker   文件: SUtils.java
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);
        }
    }
}
 
源代码8 项目: CommonUtils   文件: CommonUtils.java
public static void setImageTintColor(@NonNull ImageView view, @ColorRes int res) {
    view.setImageTintList(ColorStateList.valueOf(ContextCompat.getColor(view.getContext(), res)));
}
 
源代码9 项目: ticdesign   文件: SwipeTodoView.java
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);
}
 
源代码10 项目: LyricHere   文件: LollipopUtils.java
public static void setImageTintList(ImageView imageView, ColorStateList colorStateList) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        imageView.setImageTintList(colorStateList);
    }
}
 
private void handleUserAvatar(ImageView avatarIV, String url) {
    avatarIV.setImageTintList(null);
    ImageUtils.loadRoundCornerAvatar(avatarIV, url);
}