本文整理匯總了Java中android.graphics.drawable.Drawable.mutate方法的典型用法代碼示例。如果您正苦於以下問題:Java Drawable.mutate方法的具體用法?Java Drawable.mutate怎麽用?Java Drawable.mutate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.graphics.drawable.Drawable
的用法示例。
在下文中一共展示了Drawable.mutate方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: updateMenuItemIconColor
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
/** Update the color of a specific menu item to the given color. */
private void updateMenuItemIconColor(Menu menu, int itemId, int color) {
MenuItem menuItem = menu.findItem(itemId);
if (menuItem != null) {
Drawable menuItemIcon = menuItem.getIcon();
if (menuItemIcon != null) {
try {
menuItemIcon.mutate();
menuItemIcon.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
menuItem.setIcon(menuItemIcon);
} catch (Exception e) {
Log.w("AIC", "Failed to update menu item color", e);
}
}
}
}
示例2: colorMenuItems
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
/**
* Change action bar icon color based on text color of current action bar theme
*
* @param menu The menu
*/
public static void colorMenuItems(Menu menu) {
TypedArray typedArray = App.getContext().obtainStyledAttributes(
R.style.AppTheme_AppBarOverlay, new int[]{android.R.attr.textColorPrimary});
int themedColor = typedArray.getColor(0, Color.RED);
for (int i = 0; i < menu.size(); i++) {
Drawable icon = menu.getItem(i).getIcon();
if (icon != null) {
icon.mutate();
icon.setColorFilter(themedColor, PorterDuff.Mode.SRC_ATOP);
}
}
typedArray.recycle();
}
示例3: setContentScrim
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
public void setContentScrim(@Nullable Drawable drawable) {
Drawable drawable2 = null;
if (this.mContentScrim != drawable) {
if (this.mContentScrim != null) {
this.mContentScrim.setCallback(null);
}
if (drawable != null) {
drawable2 = drawable.mutate();
}
this.mContentScrim = drawable2;
if (this.mContentScrim != null) {
this.mContentScrim.setBounds(0, 0, getWidth(), getHeight());
this.mContentScrim.setCallback(this);
this.mContentScrim.setAlpha(this.mScrimAlpha);
}
ViewCompat.postInvalidateOnAnimation(this);
}
}
示例4: setContentScrim
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
/**
* Set the drawable to use for the content scrim from resources. Providing null will disable
* the scrim functionality.
*
* @param drawable the drawable to display
* @see #getContentScrim()
*/
public void setContentScrim(@Nullable Drawable drawable) {
if (mContentScrim != drawable) {
if (mContentScrim != null) {
mContentScrim.setCallback(null);
}
mContentScrim = drawable != null ? drawable.mutate() : null;
if (mContentScrim != null) {
mContentScrim.setBounds(0, 0, getWidth(), getHeight());
mContentScrim.setCallback(this);
mContentScrim.setAlpha(mScrimAlpha);
}
ViewCompat.postInvalidateOnAnimation(this);
}
}
示例5: setPorterDuffColorFilter
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
private static void setPorterDuffColorFilter(Drawable d, int color, Mode mode) {
if (DrawableUtils.canSafelyMutateDrawable(d)) {
d = d.mutate();
}
if (mode == null) {
mode = DEFAULT_MODE;
}
d.setColorFilter(getPorterDuffColorFilter(color, mode));
}
示例6: applyTintList
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static Drawable applyTintList(Context context, int drawableId, int tintColorId) {
final Drawable icon = getDrawable(context, drawableId);
icon.mutate();
DrawableCompat.setTintList(DrawableCompat.wrap(icon), ContextCompat.getColorStateList(context, tintColorId));
return icon;
}
示例7: onCreateOptionsMenu
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.ucrop_menu_activity, menu);
MenuItem next = menu.findItem(R.id.menu_crop);
Drawable defaultIcon = next.getIcon();
if (defaultIcon != null) {
defaultIcon.mutate();
defaultIcon.setColorFilter(this.mToolbarTextColor, Mode.SRC_ATOP);
next.setIcon(defaultIcon);
}
return true;
}
示例8: createBgDrawable
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
/**
* 使用一個 Drawable 資源生成一個具有按下效果的 StateListDrawable
*
* @param context context
* @param res drawable resource
* @param mode mode for press
* @param alpha value
* @return a stateListDrawable
*/
private static Drawable createBgDrawable(@NonNull Context context, @DrawableRes int res, @PressedMode.Mode int mode, @FloatRange(from = 0.0f, to = 1.0f) float alpha) {
Drawable normal = context.getResources().getDrawable(res);
Drawable pressed = context.getResources().getDrawable(res);
Drawable unable = context.getResources().getDrawable(res);
pressed.mutate();
unable.mutate();
pressed = getPressedStateDrawable(context, mode, alpha, pressed);
unable = getUnableStateDrawable(context, unable);
return createStateListDrawable(normal, pressed, unable);
}
示例9: setDrawableColor
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
static void setDrawableColor(Drawable drawable, int color) {
drawable.mutate();
if (drawable instanceof ShapeDrawable) {
ShapeDrawable shapeDrawable = (ShapeDrawable) drawable;
shapeDrawable.getPaint().setColor(color);
} else if (drawable instanceof GradientDrawable) {
GradientDrawable gradientDrawable = (GradientDrawable) drawable;
gradientDrawable.setColor(color);
} else if (drawable instanceof ColorDrawable) {
ColorDrawable colorDrawable = (ColorDrawable) drawable;
colorDrawable.setColor(color);
}
}
示例10: changeIconDrawableToGray
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
public static void changeIconDrawableToGray(Context context, Drawable drawable) {
if (drawable != null) {
drawable.mutate();
drawable.setColorFilter(ContextCompat
.getColor(context, R.color.dark_gray), PorterDuff.Mode.SRC_ATOP);
}
}
示例11: updateMenuItemIconColor
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
/**
* Update the color of a specific menu item to the given color.
*/
private void updateMenuItemIconColor(Menu menu, int itemId, int color) {
MenuItem menuItem = menu.findItem(itemId);
if (menuItem != null) {
Drawable menuItemIcon = menuItem.getIcon();
if (menuItemIcon != null) {
try {
menuItemIcon.mutate();
menuItemIcon.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
menuItem.setIcon(menuItemIcon);
} catch (Exception e) {
}
}
}
}
示例12: setPreferenceCategoryIcons
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
private void setPreferenceCategoryIcons() {
Drawable plusIcon = ApiCompatibilityUtils.getDrawable(getResources(), R.drawable.plus);
plusIcon.mutate();
plusIcon.setColorFilter(
ApiCompatibilityUtils.getColor(getResources(), R.color.pref_accent_color),
PorterDuff.Mode.SRC_IN);
findPreference(PREF_AUTOFILL_PROFILES).setIcon(plusIcon);
plusIcon = ApiCompatibilityUtils.getDrawable(getResources(), R.drawable.plus);
plusIcon.mutate();
plusIcon.setColorFilter(
ApiCompatibilityUtils.getColor(getResources(), R.color.pref_accent_color),
PorterDuff.Mode.SRC_IN);
findPreference(PREF_AUTOFILL_CREDIT_CARDS).setIcon(plusIcon);
}
示例13: getDrawableInt
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
@Nullable
public static int getDrawableInt(@NonNull Context context, @DrawableRes int res)
{
Drawable drawable = AppCompatDrawableManager.get().getDrawable(context, res);
drawable.mutate();
return res;
}
示例14: tintDrawable
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
/**
* Tint a drawable
*
* @param drawable The drawable to tint
* @param color The color to tint the drawable with
*/
private void tintDrawable(Drawable drawable, @ColorRes int color) {
if (drawable != null) {
drawable.mutate();
drawable.setColorFilter(ContextCompat.getColor(this.getApplicationContext(), color), PorterDuff.Mode.SRC_ATOP);
}
}
示例15: getDisabledIcon
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
/**
* Returns the Drawable object of the icon for a content type with a disabled tint.
*/
public static Drawable getDisabledIcon(int contentType, Resources resources) {
Drawable icon = ApiCompatibilityUtils.getDrawable(resources, getIcon(contentType));
icon.mutate();
int disabledColor = ApiCompatibilityUtils.getColor(resources,
R.color.primary_text_disabled_material_light);
icon.setColorFilter(disabledColor, PorterDuff.Mode.SRC_IN);
return icon;
}