當前位置: 首頁>>代碼示例>>Java>>正文


Java Drawable.mutate方法代碼示例

本文整理匯總了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);
      }
    }
  }
}
 
開發者ID:prashantsaini1,項目名稱:android-titanium-imagecropper,代碼行數:17,代碼來源:CropImageActivity.java

示例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();
}
 
開發者ID:android-gamecollection,項目名稱:gamecollection,代碼行數:21,代碼來源:AndroidResources.java

示例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);
    }
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:19,代碼來源:CollapsingToolbarLayout.java

示例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);
    }
}
 
開發者ID:QMUI,項目名稱:QMUI_Android,代碼行數:22,代碼來源:QMUICollapsingTopBarLayout.java

示例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));
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:10,代碼來源:AppCompatDrawableManager.java

示例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;
}
 
開發者ID:gigabytedevelopers,項目名稱:FireFiles,代碼行數:8,代碼來源:IconUtils.java

示例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;
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:12,代碼來源:UCropActivity.java

示例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);
}
 
開發者ID:maoruibin,項目名稱:OneDrawable,代碼行數:21,代碼來源:OneDrawable.java

示例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);
    }

}
 
開發者ID:MAXDeliveryNG,項目名稱:slideview,代碼行數:15,代碼來源:Util.java

示例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);
    }
}
 
開發者ID:MindorksOpenSource,項目名稱:android-mvvm-architecture,代碼行數:8,代碼來源:ViewUtils.java

示例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) {
            }
        }
    }
}
 
開發者ID:l465659833,項目名稱:Bigbang,代碼行數:18,代碼來源:CropImageActivity.java

示例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);
}
 
開發者ID:rkshuai,項目名稱:chromium-for-android-56-debug-video,代碼行數:16,代碼來源:AutofillPreferences.java

示例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;
}
 
開發者ID:MSay2,項目名稱:Mire,代碼行數:9,代碼來源:DrawableHelpers.java

示例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);
    }
}
 
開發者ID:hyperrail,項目名稱:hyperrail-for-android,代碼行數:13,代碼來源:RecyclerViewActivity.java

示例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;
}
 
開發者ID:rkshuai,項目名稱:chromium-for-android-56-debug-video,代碼行數:12,代碼來源:ContentSettingsResources.java


注:本文中的android.graphics.drawable.Drawable.mutate方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。