public final class DrawableInflater extends Object
Drawable
objects.
For performance reasons, inflation relies heavily on pre-processing of XML files that is done at build time. Therefore, it is not currently possible to use this inflater with an XmlPullParser over a plain XML file at runtime; it only works with an XmlPullParser returned from a compiled resource (R. something file.)
Constructor and Description |
---|
DrawableInflater(Resources res,
ClassLoader classLoader)
Constructs a new drawable inflater using the specified resources and
class loader.
|
Modifier and Type | Method and Description |
---|---|
Drawable |
inflateFromXml(String name,
XmlPullParser parser,
AttributeSet attrs,
Resources.Theme theme)
Inflates a drawable from inside an XML document using an optional
Resources.Theme . |
static Drawable |
loadDrawable(Context context,
int id)
Loads the drawable resource with the specified identifier.
|
static Drawable |
loadDrawable(Resources resources,
Resources.Theme theme,
int id)
Loads the drawable resource with the specified identifier.
|
public DrawableInflater(Resources res, ClassLoader classLoader)
res
- the resources used to resolve resource identifiersclassLoader
- the class loader used to load custom drawablespublic static Drawable loadDrawable(Context context, @DrawableRes int id)
context
- the context in which the drawable should be loadedid
- the identifier of the drawable resourcenull
if the drawable failed to loadpublic static Drawable loadDrawable(Resources resources, Resources.Theme theme, @DrawableRes int id)
resources
- the resources from which the drawable should be loadedtheme
- the theme against which the drawable should be inflatedid
- the identifier of the drawable resourcenull
if the drawable failed to loadpublic Drawable inflateFromXml(String name, XmlPullParser parser, AttributeSet attrs, Resources.Theme theme) throws XmlPullParserException, IOException
Resources.Theme
.
This method should be called on a parser positioned at a tag in an XML document defining a drawable resource. It will attempt to create a Drawable from the tag at the current position.
name
- the name of the tag at the current positionparser
- an XML parser positioned at the drawable tagattrs
- an attribute set that wraps the parsertheme
- the theme against which the drawable should be inflated, or
null
to not inflate against a themeXmlPullParserException
IOException