Skip to content

Instantly share code, notes, and snippets.

@g4s8
Created April 14, 2017 07:45
Show Gist options
  • Save g4s8/98c023dad8b2c40060da04a20f77e65d to your computer and use it in GitHub Desktop.
Save g4s8/98c023dad8b2c40060da04a20f77e65d to your computer and use it in GitHub Desktop.
final class StyledContext extends ContextThemeWrapper {
@StyleRes
private static int themeRes(@NonNull final Resources.Theme theme, @AttrRes final int themeResId) {
final TypedValue outValue = new TypedValue();
theme.resolveAttribute(themeResId, outValue, true);
return outValue.resourceId;
}
public StyledContext(final Context ctx, final @AttrRes int themeResId) {
super(ctx, themeRes(ctx.getTheme(), themeResId));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment