public void render(@Nullable final SearchSuggestionRVItem item,
@Nullable final OnClickListener listener) {
if (!hasContext() || item == null) {
return;
}
mItem = item;
if (listener != null) {
mListener = listener;
}
mSuggestionField.setText(item.getSuggestion());
if (mSuggestionField instanceof TintableBackgroundView) {
// "AppCompatTextView" and "com.android.support:appcompat-v7" are used, tint all states
ViewCompat.setBackgroundTintList(mSuggestionField,
new ColorStateList(STATES, new int[]{
AbstractColorUtils.getColor(getContext(), item.getPlaceholder()),
AbstractColorUtils.getColor(getContext(), R.color.tenor_sdk_primary_color)}));
return;
}
// "com.android.support:appcompat-v7" is likely not being used, and thus "TextView" is used
Drawable background = mSuggestionField.getBackground();
if (background instanceof TintAwareDrawable) {
// tint all states of the given drawable
DrawableCompat.setTintList(background,
new ColorStateList(STATES, new int[]{
AbstractColorUtils.getColor(getContext(), item.getPlaceholder()),
AbstractColorUtils.getColor(getContext(), R.color.tenor_sdk_primary_color)}));
return;
}
// last option, tint only the background individually
AbstractDrawableUtils.setDrawableTint(getContext(), background, item.getPlaceholder());
}
java类android.support.v4.graphics.drawable.TintAwareDrawable的实例源码
SearchSuggestionVH.java 文件源码
项目:tenor-android-demo-search
阅读 19
收藏 0
点赞 0
评论 0
DrawableTint.java 文件源码
项目:vehicle-keyboard-android
阅读 17
收藏 0
点赞 0
评论 0
@SuppressLint("RestrictedApi")
private static void setTintMode(Drawable drawable, PorterDuff.Mode mode) {
if (drawable instanceof TintAwareDrawable) {
((TintAwareDrawable) drawable).setTintMode(mode);
} else {
DrawableCompat.setTintMode(drawable, mode);
}
}
Carbon.java 文件源码
项目:Carbon
阅读 17
收藏 0
点赞 0
评论 0
public static void setTint(Drawable drawable, int tint) {
if (drawable instanceof TintAwareDrawable) {
((TintAwareDrawable) drawable).setTint(tint);
} else {
drawable.setColorFilter(new PorterDuffColorFilter(tint, PorterDuff.Mode.MULTIPLY));
}
}
Carbon.java 文件源码
项目:Carbon
阅读 18
收藏 0
点赞 0
评论 0
public static void setTintList(Drawable drawable, ColorStateList tint) {
if (drawable instanceof TintAwareDrawable) {
((TintAwareDrawable) drawable).setTintList(tint);
} else {
drawable.setColorFilter(tint == null ? null : new PorterDuffColorFilter(tint.getColorForState(drawable.getState(), tint.getDefaultColor()), PorterDuff.Mode.MULTIPLY));
}
}
Carbon.java 文件源码
项目:Carbon
阅读 18
收藏 0
点赞 0
评论 0
public static void setTintMode(Drawable drawable, PorterDuff.Mode mode) {
if (drawable instanceof TintAwareDrawable)
((TintAwareDrawable) drawable).setTintMode(mode);
}