Skip to content

Commit 5212e95

Browse files
jlnstrksjudd
authored andcommitted
Respect theme when loading Drawables while AppCompat is present (#2999)
1 parent dd7fe18 commit 5212e95

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

library/src/main/java/com/bumptech/glide/load/resource/drawable/DrawableDecoderCompat.java

+6-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import android.support.annotation.Nullable;
99
import android.support.v4.content.res.ResourcesCompat;
1010
import android.support.v7.content.res.AppCompatResources;
11+
import android.support.v7.view.ContextThemeWrapper;
1112

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

53-
private static Drawable loadDrawableV7(Context context, @DrawableRes int id) {
54-
return AppCompatResources.getDrawable(context, id);
54+
private static Drawable loadDrawableV7(Context context, @DrawableRes int id,
55+
@Nullable Theme theme) {
56+
Context resourceContext = theme != null ? new ContextThemeWrapper(context, theme) : context;
57+
return AppCompatResources.getDrawable(resourceContext, id);
5558
}
5659

5760
private static Drawable loadDrawableV4(

0 commit comments

Comments
 (0)