本文整理匯總了Java中android.support.v4.graphics.drawable.DrawableCompat.setTintList方法的典型用法代碼示例。如果您正苦於以下問題:Java DrawableCompat.setTintList方法的具體用法?Java DrawableCompat.setTintList怎麽用?Java DrawableCompat.setTintList使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.support.v4.graphics.drawable.DrawableCompat
的用法示例。
在下文中一共展示了DrawableCompat.setTintList方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onAttachedToWindow
import android.support.v4.graphics.drawable.DrawableCompat; //導入方法依賴的package包/類
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
super.setOnClickListener(this);
// setScaleType(ScaleType.CENTER_INSIDE);
// if (getTag() != null && TextUtils.equals("checked", getTag().toString())) {
// setChecked(true);
// }
if (!isInEditMode() && isTintColor) {
ColorStateList stateList = new ColorStateList(
new int[][]{{android.R.attr.state_checked}, {}},
new int[]{SkinHelper.getSkin().getThemeSubColor(), ContextCompat.getColor(getContext(), R.color.default_base_bg_disable)});
DrawableCompat.setTintList(getDrawable(), stateList);
}
}
示例2: getDrawableByState
import android.support.v4.graphics.drawable.DrawableCompat; //導入方法依賴的package包/類
private Drawable getDrawableByState(Context context, int state) {
switch (state) {
case PlaybackStateCompat.STATE_NONE:
Drawable pauseDrawable = ContextCompat.getDrawable(context, R.drawable.ic_play);
DrawableCompat.setTintList(pauseDrawable, colorPlay);
return pauseDrawable;
case PlaybackStateCompat.STATE_PLAYING:
AnimationDrawable animation = (AnimationDrawable) ContextCompat.getDrawable(context, R.drawable.equalizer);
DrawableCompat.setTintList(animation, colorPlay);
animation.start();
return animation;
case PlaybackStateCompat.STATE_PAUSED:
Drawable playDrawable = ContextCompat.getDrawable(context, R.drawable.equalizer);
DrawableCompat.setTintList(playDrawable, colorPause);
return playDrawable;
default:
Drawable noneDrawable = ContextCompat.getDrawable(context, R.drawable.ic_play);
DrawableCompat.setTintList(noneDrawable, colorPlay);
return noneDrawable;
}
}
示例3: setCustomColor
import android.support.v4.graphics.drawable.DrawableCompat; //導入方法依賴的package包/類
public void setCustomColor(@ColorInt int colorBackground, @ColorInt int colorProgress, @ColorInt int colorCircle) {
DrawableCompat.setTintList(DrawableCompat.wrap(getTrackDrawable()), new ColorStateList(
new int[][]{
new int[]{android.R.attr.state_checked},
new int[]{}
},
new int[]{
colorProgress,
colorBackground
}
));
DrawableCompat.setTintList(DrawableCompat.wrap(getThumbDrawable()), new ColorStateList(
new int[][]{
new int[]{android.R.attr.state_checked},
new int[]{}
},
new int[]{
colorCircle,
colorProgress
}
));
}
示例4: setBackgroundDrawable
import android.support.v4.graphics.drawable.DrawableCompat; //導入方法依賴的package包/類
void setBackgroundDrawable(ColorStateList backgroundTint, Mode backgroundTintMode, int rippleColor, int borderWidth) {
Drawable[] layers;
this.mShapeDrawable = DrawableCompat.wrap(createShapeDrawable());
DrawableCompat.setTintList(this.mShapeDrawable, backgroundTint);
if (backgroundTintMode != null) {
DrawableCompat.setTintMode(this.mShapeDrawable, backgroundTintMode);
}
this.mRippleDrawable = DrawableCompat.wrap(createShapeDrawable());
DrawableCompat.setTintList(this.mRippleDrawable, createColorStateList(rippleColor));
if (borderWidth > 0) {
this.mBorderDrawable = createBorderDrawable(borderWidth, backgroundTint);
layers = new Drawable[]{this.mBorderDrawable, this.mShapeDrawable, this.mRippleDrawable};
} else {
this.mBorderDrawable = null;
layers = new Drawable[]{this.mShapeDrawable, this.mRippleDrawable};
}
this.mContentBackground = new LayerDrawable(layers);
this.mShadowDrawable = new ShadowDrawableWrapper(this.mView.getResources(), this.mContentBackground, this.mShadowViewDelegate.getRadius(), this.mElevation, this.mElevation + this.mPressedTranslationZ);
this.mShadowDrawable.setAddPaddingForCorners(false);
this.mShadowViewDelegate.setBackgroundDrawable(this.mShadowDrawable);
}
示例5: forIdWithColors
import android.support.v4.graphics.drawable.DrawableCompat; //導入方法依賴的package包/類
public static Drawable forIdWithColors(Context context, int blackDrawableId, int baseId, int disabledId, int pressedId, int selectedId) {
Drawable drawable = DrawableCompat.wrap(ContextCompat.getDrawable(context, blackDrawableId));
int baseColor = ContextCompat.getColor(context, baseId);
int disabledColor = ContextCompat.getColor(context, disabledId);
int pressedColor = ContextCompat.getColor(context, pressedId);
int selectedColor = ContextCompat.getColor(context, selectedId);
int[][] states = new int[4][];
states[0] = new int[]{-android.R.attr.state_enabled};
states[1] = new int[]{android.R.attr.state_pressed};
states[2] = new int[]{android.R.attr.state_selected};
states[3] = new int[]{android.R.attr.state_enabled};
DrawableCompat.setTintList(drawable, new ColorStateList(states, new int[]{disabledColor, pressedColor, selectedColor, baseColor}));
DrawableCompat.setTintMode(drawable, Mode.SRC_IN);
return drawable;
}
示例6: install
import android.support.v4.graphics.drawable.DrawableCompat; //導入方法依賴的package包/類
public static void install(SeekBar seekBar, AttributeSet attrs) {
ThemedView.setupBackground(seekBar, attrs);
if (ThemeHelper.hasCustomAccentColor(seekBar.getContext())) {
int accentColor = ThemeHelper.getAccentColor(seekBar.getContext());
LayerDrawable ld = (LayerDrawable) seekBar.getProgressDrawable();
ld.findDrawableByLayerId(android.R.id.progress).setColorFilter(accentColor,
PorterDuff.Mode.SRC_IN);
DrawableCompat.setTintList(seekBar.getThumb().mutate(),
createSeekBarThumbColorList(seekBar.getContext()));
}
}
示例7: setTint
import android.support.v4.graphics.drawable.DrawableCompat; //導入方法依賴的package包/類
public static void setTint(@NonNull RadioButton radioButton,
@NonNull ColorStateList colors) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
radioButton.setButtonTintList(colors);
} else {
Drawable radioDrawable = ContextCompat.getDrawable(radioButton.getContext(),
R.drawable.abc_btn_radio_material);
Drawable d = DrawableCompat.wrap(radioDrawable);
DrawableCompat.setTintList(d, colors);
radioButton.setButtonDrawable(d);
}
}
示例8: setContent
import android.support.v4.graphics.drawable.DrawableCompat; //導入方法依賴的package包/類
public void setContent(@DrawableRes int iconResId, @StringRes int titleResId) {
if (iconResId > 0) {
Drawable icon = DrawableCompat.wrap(ContextCompat.getDrawable(getContext(), iconResId));
if (mIconTints != null) {
DrawableCompat.setTintList(icon, mIconTints);
}
((ImageView) findViewById(R.id.icon)).setImageDrawable(icon);
}
((TextView) findViewById(R.id.title)).setText(titleResId);
}
示例9: setTintList
import android.support.v4.graphics.drawable.DrawableCompat; //導入方法依賴的package包/類
public void setTintList(ColorStateList tint) {
if (this.mDelegateDrawable != null) {
DrawableCompat.setTintList(this.mDelegateDrawable, tint);
return;
}
VectorDrawableCompatState state = this.mVectorState;
if (state.mTint != tint) {
state.mTint = tint;
this.mTintFilter = updateTintFilter(this.mTintFilter, tint, state.mTintMode);
invalidateSelf();
}
}
示例10: tintDrawable
import android.support.v4.graphics.drawable.DrawableCompat; //導入方法依賴的package包/類
public static Drawable tintDrawable(Context context, Drawable drawable, int tintAttr) {
// start of FIX - tinting the drawable manually because the android:tint attribute crashes the app
Drawable wrapped = DrawableCompat.wrap(drawable);
TypedArray arr = context.obtainStyledAttributes(new int[]{tintAttr});
ColorStateList tintList = Utils.getColorStateList(context, arr, 0);
arr.recycle();
if (tintList != null) {
DrawableCompat.setTintList(wrapped, tintList);
}
return wrapped;
// end of FIX
}
示例11: setFabIconTint
import android.support.v4.graphics.drawable.DrawableCompat; //導入方法依賴的package包/類
@Override
public BottomSheetNumberPadTimePickerThemer setFabIconTint(ColorStateList tint) {
if (tint != null) {
int[] colors = extractColors(tint, STATES_FAB_COLORS);
if (mFabIconTintAnimator != null) {
mFabIconTintAnimator.setIntValues(colors);
} else {
mFabIconTintAnimator = createFabIconTintAnimator(colors);
}
}
DrawableCompat.setTintList(mOkButton.getDrawable(), tint);
return this;
}
示例12: setBackgroundDrawable
import android.support.v4.graphics.drawable.DrawableCompat; //導入方法依賴的package包/類
void setBackgroundDrawable(ColorStateList backgroundTint,
PorterDuff.Mode backgroundTintMode, int rippleColor, int borderWidth) {
// Now we need to tint the original background with the tint, using
// an InsetDrawable if we have a border width
mShapeDrawable = DrawableCompat.wrap(createShapeDrawable());
DrawableCompat.setTintList(mShapeDrawable, backgroundTint);
if (backgroundTintMode != null) {
DrawableCompat.setTintMode(mShapeDrawable, backgroundTintMode);
}
// Now we created a mask Drawable which will be used for touch feedback.
GradientDrawable touchFeedbackShape = createShapeDrawable();
// We'll now wrap that touch feedback mask drawable with a ColorStateList. We do not need
// to inset for any border here as LayerDrawable will nest the padding for us
mRippleDrawable = DrawableCompat.wrap(touchFeedbackShape);
DrawableCompat.setTintList(mRippleDrawable, createColorStateList(rippleColor));
final Drawable[] layers;
if (borderWidth > 0) {
mBorderDrawable = createBorderDrawable(borderWidth, backgroundTint);
layers = new Drawable[] {mBorderDrawable, mShapeDrawable, mRippleDrawable};
} else {
mBorderDrawable = null;
layers = new Drawable[] {mShapeDrawable, mRippleDrawable};
}
mContentBackground = new LayerDrawable(layers);
mShadowDrawable = new ShadowDrawableWrapper(
mView.getContext(),
mContentBackground,
mShadowViewDelegate.getRadius(),
mElevation,
mElevation + mPressedTranslationZ);
mShadowDrawable.setAddPaddingForCorners(false);
mShadowViewDelegate.setBackgroundDrawable(mShadowDrawable);
}
示例13: render
import android.support.v4.graphics.drawable.DrawableCompat; //導入方法依賴的package包/類
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());
}
示例14: tintDrawable
import android.support.v4.graphics.drawable.DrawableCompat; //導入方法依賴的package包/類
public Drawable tintDrawable(Drawable drawable, ColorStateList colors) {
Drawable wrappedDrawable = DrawableCompat.wrap(drawable);
DrawableCompat.setTintList(wrappedDrawable, colors);
return wrappedDrawable;
}
示例15: initSearchView
import android.support.v4.graphics.drawable.DrawableCompat; //導入方法依賴的package包/類
private void initSearchView() {
SearchView searchView = mBinding.svSearch;
//設置搜索框左邊距
LinearLayout editFrame = (LinearLayout) findViewById(R.id.search_edit_frame);
LinearLayout.LayoutParams editP = (LayoutParams) editFrame.getLayoutParams();
editP.leftMargin = 0;
editP.rightMargin = 0;
ImageView imageView = (ImageView) findViewById(R.id.search_mag_icon);
imageView.setAdjustViewBounds(true);
imageView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
LinearLayout.LayoutParams lp3 = (LayoutParams) imageView.getLayoutParams();
lp3.gravity = Gravity.CENTER_VERTICAL;
lp3.leftMargin = (int) (DensityUtil.dip2px(8f) * DensityUtil.getBaseScale(getContext()));
lp3.rightMargin = (int) (DensityUtil.dip2px(-2f) * DensityUtil.getBaseScale(getContext()));
View view = searchView.findViewById(R.id.search_plate);
view.setBackgroundColor(getResources().getColor(R.color.colorTransparent));
EditText editText = (EditText) searchView.findViewById(R.id.search_src_text);
editText.setBackgroundColor(Color.TRANSPARENT);
editText.setTextSize(11.5f);
editText.setTextColor(getResources().getColor(R.color.colorText));
editText.setHintTextColor(getResources().getColor(R.color.colorHint));
try {
Field fCursorDrawableRes = TextView.class.getDeclaredField("mCursorDrawableRes");
fCursorDrawableRes.setAccessible(true);
int mCursorDrawableRes = fCursorDrawableRes.getInt(editText);
Field fEditor = TextView.class.getDeclaredField("mEditor");
fEditor.setAccessible(true);
Object editor = fEditor.get(editText);
Class<?> clazz = editor.getClass();
Field fCursorDrawable = clazz.getDeclaredField("mCursorDrawable");
fCursorDrawable.setAccessible(true);
if (mCursorDrawableRes <= 0) return;
Drawable cursorDrawable = ContextCompat.getDrawable(searchView.getContext(), mCursorDrawableRes);
if (cursorDrawable == null) return;
Drawable tintDrawable = DrawableCompat.wrap(cursorDrawable);
DrawableCompat.setTintList(tintDrawable, ColorStateList.valueOf(ContextCompat.getColor(getContext(), R.color.bg_search)));
Drawable[] drawables = new Drawable[]{tintDrawable, tintDrawable};
fCursorDrawable.set(editor, drawables);
} catch (Throwable t) {
t.printStackTrace();
}
}