ThemeUtils.java 文件源码

java
阅读 42 收藏 0 点赞 0 评论 0

项目:Xndroid 作者:
/**
 * Gets the icon with an applied color filter
 * for the correct theme.
 *
 * @param context the context to use.
 * @param res     the drawable resource to use.
 * @param dark    true for icon suitable for use with a dark theme,
 *                false for icon suitable for use with a light theme.
 * @return a themed icon.
 */
@NonNull
public static Bitmap getThemedBitmap(@NonNull Context context, @DrawableRes int res, boolean dark) {
    int color = dark ? getIconDarkThemeColor(context) : getIconLightThemeColor(context);

    Bitmap sourceBitmap = getBitmapFromVectorDrawable(context, res);
    Bitmap resultBitmap = Bitmap.createBitmap(sourceBitmap.getWidth(), sourceBitmap.getHeight(),
        Bitmap.Config.ARGB_8888);
    Paint p = new Paint();
    ColorFilter filter = new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_IN);
    p.setColorFilter(filter);
    Canvas canvas = new Canvas(resultBitmap);
    canvas.drawBitmap(sourceBitmap, 0, 0, p);
    sourceBitmap.recycle();
    return resultBitmap;
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号