代码拉取完成,页面将自动刷新
#效果图
#核心代码
/**
* 实现ImageView的变色
*
* @param imageView
* @param color
*/
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 {
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);
}
}
/**
* 实现textView的Compound图标变色
*
* @param textView
* @param color
* @param isChangeTextColor 是否改变字的颜色
*/
public static void setCompoundTint(@NonNull TextView textView, @ColorInt int color, boolean isChangeTextColor) {
ColorStateList s1 = ColorStateList.valueOf(color);
if (isChangeTextColor) {
textView.setTextColor(s1);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
textView.setCompoundDrawableTintList(s1);
} else {
PorterDuff.Mode mode = PorterDuff.Mode.SRC_IN;
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1) {
mode = PorterDuff.Mode.MULTIPLY;
}
for (Drawable d : textView.getCompoundDrawables()) {
if (d != null)
d.setColorFilter(color, mode);
}
}
}
/**
* @param button
* @param color
*/
public static void setTint(@NonNull Button button, @ColorInt int color) {
ColorStateList s1 = ColorStateList.valueOf(color);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
button.setBackgroundTintList(s1);
} else {
PorterDuff.Mode mode = PorterDuff.Mode.SRC_IN;
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1) {
mode = PorterDuff.Mode.MULTIPLY;
}
if (button.getBackground() != null)
button.getBackground().setColorFilter(color, mode);
}
}
/**
* 处理SeekBar的变色
*
* @param seekBar
* @param color
*/
public static void setTint(@NonNull SeekBar seekBar, @ColorInt int color) {
ColorStateList s1 = ColorStateList.valueOf(color);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
seekBar.setThumbTintList(s1);
seekBar.setProgressTintList(s1);
} else if (Build.VERSION.SDK_INT > Build.VERSION_CODES.GINGERBREAD_MR1) {
Drawable progressDrawable = DrawableCompat.wrap(seekBar.getProgressDrawable());
seekBar.setProgressDrawable(progressDrawable);
DrawableCompat.setTintList(progressDrawable, s1);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
Drawable thumbDrawable = DrawableCompat.wrap(seekBar.getThumb());
DrawableCompat.setTintList(thumbDrawable, s1);
seekBar.setThumb(thumbDrawable);
}
} else {
PorterDuff.Mode mode = PorterDuff.Mode.SRC_IN;
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1) {
mode = PorterDuff.Mode.MULTIPLY;
}
if (seekBar.getIndeterminateDrawable() != null)
seekBar.getIndeterminateDrawable().setColorFilter(color, mode);
if (seekBar.getProgressDrawable() != null)
seekBar.getProgressDrawable().setColorFilter(color, mode);
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。