本文整理匯總了Java中android.support.v4.graphics.drawable.DrawableCompat類的典型用法代碼示例。如果您正苦於以下問題:Java DrawableCompat類的具體用法?Java DrawableCompat怎麽用?Java DrawableCompat使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
DrawableCompat類屬於android.support.v4.graphics.drawable包,在下文中一共展示了DrawableCompat類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: setStatusBarBackground
import android.support.v4.graphics.drawable.DrawableCompat; //導入依賴的package包/類
public void setStatusBarBackground(@Nullable Drawable bg) {
Drawable drawable = null;
if (this.mStatusBarBackground != bg) {
if (this.mStatusBarBackground != null) {
this.mStatusBarBackground.setCallback(null);
}
if (bg != null) {
drawable = bg.mutate();
}
this.mStatusBarBackground = drawable;
if (this.mStatusBarBackground != null) {
if (this.mStatusBarBackground.isStateful()) {
this.mStatusBarBackground.setState(getDrawableState());
}
DrawableCompat.setLayoutDirection(this.mStatusBarBackground, ViewCompat.getLayoutDirection(this));
this.mStatusBarBackground.setVisible(getVisibility() == 0, false);
this.mStatusBarBackground.setCallback(this);
}
ViewCompat.postInvalidateOnAnimation(this);
}
}
示例2: onCreate
import android.support.v4.graphics.drawable.DrawableCompat; //導入依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
marqueeView1 = (SimpleMarqueeView) findViewById(R.id.marqueeView1);
marqueeView2 = (SimpleMarqueeView) findViewById(R.id.marqueeView2);
marqueeView3 = (SimpleMarqueeView) findViewById(R.id.marqueeView3);
yellowSpeaker = (ImageView) findViewById(R.id.yellowSpeaker);
marqueeView4 = (MarqueeView) findViewById(R.id.marqueeView4);
marqueeView5 = (SimpleMarqueeView) findViewById(R.id.marqueeView5);
marqueeView6 = (SimpleMarqueeView) findViewById(R.id.marqueeView6);
DrawableCompat.setTint(DrawableCompat.wrap(yellowSpeaker.getDrawable().mutate()), getResources().getColor(R.color.yellow));
initMarqueeView1();
initMarqueeView2();
initMarqueeView3();
initMarqueeView4();
initMarqueeView5();
initMarqueeView6();
}
示例3: getTintedDrawable
import android.support.v4.graphics.drawable.DrawableCompat; //導入依賴的package包/類
@UiThread // Implicit synchronization for use of shared resource VALUE.
public static Drawable getTintedDrawable(Context context,
@DrawableRes int id, @AttrRes int tintAttrId) {
boolean attributeFound = context.getTheme().resolveAttribute(tintAttrId, VALUE, true);
if (!attributeFound) {
throw new Resources.NotFoundException("Required tint color attribute with name "
+ context.getResources().getResourceEntryName(tintAttrId)
+ " and attribute ID "
+ tintAttrId
+ " was not found.");
}
Drawable drawable = ContextCompat.getDrawable(context, id);
drawable = DrawableCompat.wrap(drawable.mutate());
int color = ContextCompat.getColor(context, VALUE.resourceId);
DrawableCompat.setTint(drawable, color);
return drawable;
}
示例4: setTint
import android.support.v4.graphics.drawable.DrawableCompat; //導入依賴的package包/類
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);
}
}
示例5: initializeView
import android.support.v4.graphics.drawable.DrawableCompat; //導入依賴的package包/類
private void initializeView() {
Context context = getContext();
frontCameraDrawable = ContextCompat.getDrawable(context, R.drawable.ic_camera_front_white_24dp);
frontCameraDrawable = DrawableCompat.wrap(frontCameraDrawable);
DrawableCompat.setTintList(frontCameraDrawable.mutate(), ContextCompat.getColorStateList(context, R.drawable.switch_camera_mode_selector));
rearCameraDrawable = ContextCompat.getDrawable(context, R.drawable.ic_camera_rear_white_24dp);
rearCameraDrawable = DrawableCompat.wrap(rearCameraDrawable);
DrawableCompat.setTintList(rearCameraDrawable.mutate(), ContextCompat.getColorStateList(context, R.drawable.switch_camera_mode_selector));
setBackgroundResource(R.drawable.circle_frame_background_dark);
displayBackCamera();
padding = Utils.convertDipToPixels(context, padding);
setPadding(padding, padding, padding, padding);
displayBackCamera();
}
示例6: 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);
}
示例7: tint
import android.support.v4.graphics.drawable.DrawableCompat; //導入依賴的package包/類
/**
* Tint the radio button
*
* @param radioButton the radio button
* @param color the color
*/
public static void tint(@NonNull RadioButton radioButton, @ColorInt int color) {
final int disabledColor = getDisabledColor(radioButton.getContext());
ColorStateList sl = new ColorStateList(new int[][]{
new int[]{android.R.attr.state_enabled, -android.R.attr.state_checked},
new int[]{android.R.attr.state_enabled, android.R.attr.state_checked},
new int[]{-android.R.attr.state_enabled, -android.R.attr.state_checked},
new int[]{-android.R.attr.state_enabled, android.R.attr.state_checked}
}, new int[]{
getThemeAttrColor(radioButton.getContext(), R.attr.colorControlNormal),
color,
disabledColor,
disabledColor
});
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
radioButton.setButtonTintList(sl);
} else {
Drawable radioDrawable = ContextCompat.getDrawable(radioButton.getContext(), R.drawable.abc_btn_radio_material);
Drawable d = DrawableCompat.wrap(radioDrawable);
DrawableCompat.setTintList(d, sl);
radioButton.setButtonDrawable(d);
}
}
示例8: setIconColor
import android.support.v4.graphics.drawable.DrawableCompat; //導入依賴的package包/類
/**
* Set a color of icon on left side.
*
* @param iconColor a icon color
*/
public void setIconColor(@ColorInt final int iconColor) {
mIconColor = iconColor;
if (mDisplayMode == MODE_ICON && mIconView.getDrawable() != null) {
ViewUtils.setIconColor(mIconView,
Color.alpha(mIconColor) == 0 ? mDefaultColor : mIconColor);
} else if (mDisplayMode == MODE_CIRCULAR_ICON
&& mCircularIconView.getIconDrawable() != null) {
mCircularIconView.setMask(Color.alpha(mIconColor) == 0);
Drawable wrappedDrawable = DrawableCompat.wrap(mCircularIconView.getIconDrawable());
DrawableCompat.setTint(wrappedDrawable,
Color.alpha(mIconColor) == 0 ? Color.WHITE : mIconColor);
mCircularIconView.setIconDrawable(wrappedDrawable);
}
}
示例9: drawableToBitmap
import android.support.v4.graphics.drawable.DrawableCompat; //導入依賴的package包/類
public Bitmap drawableToBitmap(Drawable drawable) {
Bitmap bitmap = null;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && (drawable instanceof VectorDrawable || drawable instanceof VectorDrawableCompat)) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
drawable = (DrawableCompat.wrap(drawable)).mutate();
}
bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(),
drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
drawable.draw(canvas);
} else if (drawable instanceof BitmapDrawable) {
bitmap = ((BitmapDrawable) drawable).getBitmap();
}
return bitmap;
}
示例10: init
import android.support.v4.graphics.drawable.DrawableCompat; //導入依賴的package包/類
private void init(Context context, AttributeSet attrs, int defStyleAttr) {
TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.ColorRatingBar, defStyleAttr, 0);
int progressColor = a.getColor(R.styleable.ColorRatingBar_progress_color, ContextCompat.getColor(context, R.color.colorPrimary));
// int halfColor = a.getColor(R.styleable.ColorRatingBar_half_color, ContextCompat.getColor(context, R.color.colorAccent));
int emptyColor = a.getColor(R.styleable.ColorRatingBar_empty_color, ContextCompat.getColor(context, R.color.colorAccent));
boolean changeable = a.getBoolean(R.styleable.ColorRatingBar_changeable, true);
LayerDrawable stars = (LayerDrawable) getProgressDrawable();
// Filled stars
setRatingStarColor(DrawableCompat.wrap(stars.getDrawable(2)), progressColor);
// Half filled stars
setRatingStarColor(DrawableCompat.wrap(stars.getDrawable(1)), progressColor);
// Empty stars
setRatingStarColor(DrawableCompat.wrap(stars.getDrawable(0)), emptyColor);
setIsIndicator(!changeable);
}
示例11: initializeView
import android.support.v4.graphics.drawable.DrawableCompat; //導入依賴的package包/類
private void initializeView() {
photoDrawable = ContextCompat.getDrawable(context, R.drawable.ic_photo_camera_white_24dp);
photoDrawable = DrawableCompat.wrap(photoDrawable);
DrawableCompat.setTintList(photoDrawable.mutate(), ContextCompat.getColorStateList(context, R.drawable.switch_camera_mode_selector));
videoDrawable = ContextCompat.getDrawable(context, R.drawable.ic_videocam_white_24dp);
videoDrawable = DrawableCompat.wrap(videoDrawable);
DrawableCompat.setTintList(videoDrawable.mutate(), ContextCompat.getColorStateList(context, R.drawable.switch_camera_mode_selector));
setBackgroundResource(R.drawable.circle_frame_background_dark);
// setBackgroundResource(R.drawable.circle_frame_background);
setOnClickListener(new MediaActionClickListener());
setIcons();
padding = Utils.convertDipToPixels(context, padding);
setPadding(padding, padding, padding, padding);
}
示例12: applyButtonTint
import android.support.v4.graphics.drawable.DrawableCompat; //導入依賴的package包/類
void applyButtonTint() {
Drawable buttonDrawable = CompoundButtonCompat.getButtonDrawable(this.mView);
if (buttonDrawable == null) {
return;
}
if (this.mHasButtonTint || this.mHasButtonTintMode) {
buttonDrawable = DrawableCompat.wrap(buttonDrawable).mutate();
if (this.mHasButtonTint) {
DrawableCompat.setTintList(buttonDrawable, this.mButtonTintList);
}
if (this.mHasButtonTintMode) {
DrawableCompat.setTintMode(buttonDrawable, this.mButtonTintMode);
}
if (buttonDrawable.isStateful()) {
buttonDrawable.setState(this.mView.getDrawableState());
}
this.mView.setButtonDrawable(buttonDrawable);
}
}
示例13: bind
import android.support.v4.graphics.drawable.DrawableCompat; //導入依賴的package包/類
public void bind(ServerListAdapter adapter, ServerConnectionInfo connectionInfo) {
mConnectionInfo = connectionInfo;
Drawable d = DrawableCompat.wrap(mIconBg.getBackground());
if (connectionInfo.isConnected()) {
DrawableCompat.setTint(d, adapter.mColorConnected);
mIcon.setImageResource(R.drawable.ic_server_connected);
int channels = connectionInfo.getChannels().size();
mDesc.setText(mDesc.getResources().getQuantityString(R.plurals.server_list_connected, channels, channels));
} else if (connectionInfo.isConnecting()) {
DrawableCompat.setTint(d, adapter.mColorConnecting);
mIcon.setImageResource(R.drawable.ic_refresh);
mDesc.setText(R.string.server_list_connecting);
} else {
DrawableCompat.setTint(d, adapter.mColorDisconnected);
mIcon.setImageResource(R.drawable.ic_close);
mDesc.setText(R.string.server_list_disconnected);
}
mIconBg.setBackgroundDrawable(d);
mName.setText(connectionInfo.getName());
}
示例14: setStyle
import android.support.v4.graphics.drawable.DrawableCompat; //導入依賴的package包/類
void setStyle(TextSection section) {
switch (section.getAlignment()) {
case TextSection.LEFT:
DrawableCompat.setTint(mImageAlignLeft.getDrawable(), 0xff24cf5f);
DrawableCompat.setTint(mImageAlignCenter.getDrawable(), 0xFFFFFFFF);
DrawableCompat.setTint(mImageAlignRight.getDrawable(), 0xFFFFFFFF);
break;
case TextSection.CENTER:
DrawableCompat.setTint(mImageAlignLeft.getDrawable(), 0xFFFFFFFF);
DrawableCompat.setTint(mImageAlignCenter.getDrawable(), 0xff24cf5f);
DrawableCompat.setTint(mImageAlignRight.getDrawable(), 0xFFFFFFFF);
break;
case TextSection.RIGHT:
DrawableCompat.setTint(mImageAlignLeft.getDrawable(), 0xFFFFFFFF);
DrawableCompat.setTint(mImageAlignCenter.getDrawable(), 0xFFFFFFFF);
DrawableCompat.setTint(mImageAlignRight.getDrawable(), 0xff24cf5f);
break;
}
}
示例15: positionSelectorLikeFocusCompat
import android.support.v4.graphics.drawable.DrawableCompat; //導入依賴的package包/類
protected void positionSelectorLikeFocusCompat(int position, View sel) {
boolean manageState;
boolean z = true;
Drawable selector = getSelector();
if (selector == null || position == -1) {
manageState = false;
} else {
manageState = true;
}
if (manageState) {
selector.setVisible(false, false);
}
positionSelectorCompat(position, sel);
if (manageState) {
Rect bounds = this.mSelectorRect;
float x = bounds.exactCenterX();
float y = bounds.exactCenterY();
if (getVisibility() != 0) {
z = false;
}
selector.setVisible(z, false);
DrawableCompat.setHotspot(selector, x, y);
}
}