4

I want to use Context or Resources to obtain a themed drawable, and my minSDK is 15. How do I go about doing it?

The developer documentation for Resources has a note which says,

Note: To obtain a themed drawable, use Context.getDrawable(int) or getDrawable(int, Theme) passing the desired theme.

Both Context.getDrawable(int) and Resources.getDrawable(int, Theme) were added in API 21, so I can't use them. If I look at [ResourcesCompat documentation](http://developer.android.com/reference/android/support/v4/content/res/ResourcesCompat.html#getDrawable(android.content.res.Resources, int, android.content.res.Resources.Theme)), it has a similar limitation:

Prior to API level 21, the theme will not be applied and this method simply calls through to getDrawable(int).

Is there really no way to obtain a themed drawable before API level 21?

I can provide sample code if required, but it's really just an attrs.xml which specifies the attribute, themes.xml which defines that attribute, ContextThemeWrapper which applies it, and a drawable/foobar.xml which uses <solid android:color="?attr/MY_ATTRIBUTE" />.

Rohan Dhruva
  • 1,194
  • 1
  • 10
  • 20

1 Answers1

1

After posting the question, I found out that you can't use ?attr/ in drawable XML files before API level 21. See How to reference style attributes from a drawable? for more details.

Community
  • 1
  • 1
Rohan Dhruva
  • 1,194
  • 1
  • 10
  • 20