Skip to content

Commit

Permalink
Respect theme when loading Drawables while AppCompat is present (#2999)
Browse files Browse the repository at this point in the history
  • Loading branch information
jlnstrk authored and sjudd committed Mar 30, 2018
1 parent dd7fe18 commit 5212e95
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import android.support.annotation.Nullable;
import android.support.v4.content.res.ResourcesCompat;
import android.support.v7.content.res.AppCompatResources;
import android.support.v7.view.ContextThemeWrapper;

/**
* Handles decoding Drawables with the v7 support library if present and falling back to the v4
Expand Down Expand Up @@ -38,7 +39,7 @@ public static Drawable getDrawable(Context context, @DrawableRes int id, @Nullab
// Race conditions may cause us to attempt to load using v7 more than once. That's ok since
// this check is a modest optimization and the output will be correct anyway.
if (shouldCallAppCompatResources) {
return loadDrawableV7(context, id);
return loadDrawableV7(context, id, theme);
}
} catch (NoClassDefFoundError error) {
shouldCallAppCompatResources = false;
Expand All @@ -50,8 +51,10 @@ public static Drawable getDrawable(Context context, @DrawableRes int id, @Nullab
return loadDrawableV4(context, id, theme != null ? theme : context.getTheme());
}

private static Drawable loadDrawableV7(Context context, @DrawableRes int id) {
return AppCompatResources.getDrawable(context, id);
private static Drawable loadDrawableV7(Context context, @DrawableRes int id,
@Nullable Theme theme) {
Context resourceContext = theme != null ? new ContextThemeWrapper(context, theme) : context;
return AppCompatResources.getDrawable(resourceContext, id);
}

private static Drawable loadDrawableV4(
Expand Down

0 comments on commit 5212e95

Please sign in to comment.