public class Resources extends Object
getAssets()
) and
provides a high-level API for getting typed data from the assets.
The Android resource system keeps track of all non-code assets associated with an
application. You can use this class to access your application's resources. You can generally
acquire the Resources
instance associated with your application
with getResources()
.
The Android SDK tools compile your application's resources into the application binary
at build time. To use a resource, you must install it correctly in the source tree (inside
your project's res/
directory) and build your application. As part of the build
process, the SDK tools generate symbols for each resource, which you can use in your application
code to access the resources.
Using application resources makes it easy to update various characteristics of your application without modifying code, and—by providing sets of alternative resources—enables you to optimize your application for a variety of device configurations (such as for different languages and screen sizes). This is an important aspect of developing Android applications that are compatible on different types of devices.
For more information about using resources, see the documentation about Application Resources.
Modifier and Type | Class and Description |
---|---|
static class |
Resources.NotFoundException
This exception is thrown by the resource APIs when a requested resource
can not be found.
|
class |
Resources.Theme
This class holds the current attribute values for a particular theme.
|
Constructor and Description |
---|
Resources(AssetManager assets,
DisplayMetrics metrics,
Configuration config)
Deprecated.
Resources should not be constructed by apps.
See
Context.createConfigurationContext(Configuration) . |
Resources(ClassLoader classLoader)
Creates a new Resources object with CompatibilityInfo.
|
Modifier and Type | Method and Description |
---|---|
int |
calcConfigChanges(Configuration config)
Called by ConfigurationBoundResourceCacheTest.
|
void |
finishPreloading()
Called by zygote when it is done preloading resources, to change back
to normal Resources operation.
|
void |
flushLayoutCache()
Call this to remove all cached loaded layout resources from the
Resources object.
|
XmlResourceParser |
getAnimation(int id)
Return an XmlResourceParser through which you can read an animation
description for the given resource ID.
|
ConfigurationBoundResourceCache<Animator> |
getAnimatorCache()
Used by AnimatorInflater.
|
AssetManager |
getAssets()
Retrieve underlying AssetManager storage for these resources.
|
boolean |
getBoolean(int id)
Return a boolean associated with a particular resource ID.
|
ClassLoader |
getClassLoader() |
int |
getColor(int id)
Deprecated.
Use
getColor(int, Theme) instead. |
int |
getColor(int id,
Resources.Theme theme)
Returns a themed color integer associated with a particular resource ID.
|
ColorStateList |
getColorStateList(int id)
Deprecated.
Use
getColorStateList(int, Theme) instead. |
ColorStateList |
getColorStateList(int id,
Resources.Theme theme)
Returns a themed color state list associated with a particular resource
ID.
|
CompatibilityInfo |
getCompatibilityInfo()
Return the compatibility mode information for the application.
|
Configuration |
getConfiguration()
Return the current configuration that is in effect for this resource
object.
|
float |
getDimension(int id)
Retrieve a dimensional for a particular resource ID.
|
int |
getDimensionPixelOffset(int id)
Retrieve a dimensional for a particular resource ID for use
as an offset in raw pixels.
|
int |
getDimensionPixelSize(int id)
Retrieve a dimensional for a particular resource ID for use
as a size in raw pixels.
|
DisplayAdjustments |
getDisplayAdjustments() |
DisplayMetrics |
getDisplayMetrics()
Return the current display metrics that are in effect for this resource
object.
|
Drawable |
getDrawable(int id)
Deprecated.
Use
getDrawable(int, Theme) instead. |
Drawable |
getDrawable(int id,
Resources.Theme theme)
Return a drawable object associated with a particular resource ID and
styled for the specified theme.
|
Drawable |
getDrawableForDensity(int id,
int density)
Deprecated.
Use
getDrawableForDensity(int, int, Theme) instead. |
Drawable |
getDrawableForDensity(int id,
int density,
Resources.Theme theme)
Return a drawable object associated with a particular resource ID for the
given screen density in DPI and styled for the specified theme.
|
DrawableInflater |
getDrawableInflater() |
float |
getFloat(int id)
Retrieve a floating-point value for a particular resource ID.
|
float |
getFraction(int id,
int base,
int pbase)
Retrieve a fractional unit for a particular resource ID.
|
int |
getIdentifier(String name,
String defType,
String defPackage)
Return a resource identifier for the given resource name.
|
ResourcesImpl |
getImpl() |
int[] |
getIntArray(int id)
Return the int array associated with a particular resource ID.
|
int |
getInteger(int id)
Return an integer associated with a particular resource ID.
|
XmlResourceParser |
getLayout(int id)
Return an XmlResourceParser through which you can read a view layout
description for the given resource ID.
|
Movie |
getMovie(int id)
Return a movie object associated with the particular resource ID.
|
LongSparseArray<Drawable.ConstantState> |
getPreloadedDrawables() |
String |
getQuantityString(int id,
int quantity)
Returns the string necessary for grammatically correct pluralization
of the given resource ID for the given quantity.
|
String |
getQuantityString(int id,
int quantity,
Object... formatArgs)
Formats the string necessary for grammatically correct pluralization
of the given resource ID for the given quantity, using the given arguments.
|
CharSequence |
getQuantityText(int id,
int quantity)
Returns the character sequence necessary for grammatically correct pluralization
of the given resource ID for the given quantity.
|
String |
getResourceEntryName(int resid)
Return the entry name for a given resource identifier.
|
String |
getResourceName(int resid)
Return the full name for a given resource identifier.
|
String |
getResourcePackageName(int resid)
Return the package name for a given resource identifier.
|
String |
getResourceTypeName(int resid)
Return the type name for a given resource identifier.
|
Configuration[] |
getSizeConfigurations() |
ConfigurationBoundResourceCache<StateListAnimator> |
getStateListAnimatorCache()
Used by AnimatorInflater.
|
String |
getString(int id)
Return the string value associated with a particular resource ID.
|
String |
getString(int id,
Object... formatArgs)
Return the string value associated with a particular resource ID,
substituting the format arguments as defined in
Formatter
and String.format(java.lang.String, java.lang.Object...) . |
String[] |
getStringArray(int id)
Return the string array associated with a particular resource ID.
|
static Resources |
getSystem()
Return a global shared Resources object that provides access to only
system resources (no application resources), and is not configured for
the current screen (can not use dimension units, does not change based
on orientation, etc).
|
CharSequence |
getText(int id)
Return the string value associated with a particular resource ID.
|
CharSequence |
getText(int id,
CharSequence def)
Return the string value associated with a particular resource ID.
|
CharSequence[] |
getTextArray(int id)
Return the styled text array associated with a particular resource ID.
|
void |
getValue(int id,
TypedValue outValue,
boolean resolveRefs)
Return the raw data associated with a particular resource ID.
|
void |
getValue(String name,
TypedValue outValue,
boolean resolveRefs)
Return the raw data associated with a particular resource ID.
|
void |
getValueForDensity(int id,
int density,
TypedValue outValue,
boolean resolveRefs)
Get the raw value associated with a resource with associated density.
|
XmlResourceParser |
getXml(int id)
Return an XmlResourceParser through which you can read a generic XML
resource for the given resource ID.
|
ComplexColor |
loadComplexColor(TypedValue value,
int id,
Resources.Theme theme) |
Resources.Theme |
newTheme()
Generate a new Theme object for this set of Resources.
|
TypedArray |
obtainAttributes(AttributeSet set,
int[] attrs)
Retrieve a set of basic attribute values from an AttributeSet, not
performing styling of them using a theme and/or style resources.
|
static TypedArray |
obtainAttributes(Resources res,
Resources.Theme theme,
AttributeSet set,
int[] attrs)
Obtains styled attributes from the theme, if available, or unstyled
resources if the theme is null.
|
TypedArray |
obtainTypedArray(int id)
Return an array of heterogeneous values.
|
InputStream |
openRawResource(int id)
Open a data stream for reading a raw resource.
|
InputStream |
openRawResource(int id,
TypedValue value)
Open a data stream for reading a raw resource.
|
AssetFileDescriptor |
openRawResourceFd(int id)
Open a file descriptor for reading a raw resource.
|
void |
parseBundleExtra(String tagName,
AttributeSet attrs,
Bundle outBundle)
Parse a name/value pair out of an XML tag holding that data.
|
void |
parseBundleExtras(XmlResourceParser parser,
Bundle outBundle)
Parse a series of
<extra> tags from
an XML file. |
static boolean |
resourceHasPackage(int resid)
Return true if given resource identifier includes a package.
|
static int |
selectDefaultTheme(int curTheme,
int targetSdkVersion)
Returns the most appropriate default theme for the specified target SDK version.
|
static int |
selectSystemTheme(int curTheme,
int targetSdkVersion,
int orig,
int holo,
int dark,
int deviceDefault) |
void |
setCompatibilityInfo(CompatibilityInfo ci)
This is just for testing.
|
void |
setImpl(ResourcesImpl impl)
Set the underlying implementation (containing all the resources and caches)
and updates all Theme references to new implementations as well.
|
void |
startPreloading()
Start preloading of resource data using this Resources object.
|
void |
updateConfiguration(Configuration config,
DisplayMetrics metrics)
Deprecated.
|
void |
updateConfiguration(Configuration config,
DisplayMetrics metrics,
CompatibilityInfo compat) |
static void |
updateSystemConfiguration(Configuration config,
DisplayMetrics metrics,
CompatibilityInfo compat)
Update the system resources configuration if they have previously
been initialized.
|
@Deprecated public Resources(AssetManager assets, DisplayMetrics metrics, Configuration config)
Context.createConfigurationContext(Configuration)
.assets
- Previously created AssetManager.metrics
- Current display metrics to consider when
selecting/computing resource values.config
- Desired device configuration to consider when
selecting/computing resource values (optional).public Resources(ClassLoader classLoader)
classLoader
- class loader for the package used to load custom
resource classes, may be null
to use system
class loaderpublic static int selectDefaultTheme(int curTheme, int targetSdkVersion)
curTheme
- The current theme, or 0 if not specified.targetSdkVersion
- The target SDK version.public static int selectSystemTheme(int curTheme, int targetSdkVersion, int orig, int holo, int dark, int deviceDefault)
public static Resources getSystem()
public void setImpl(ResourcesImpl impl)
public ResourcesImpl getImpl()
public ClassLoader getClassLoader()
public final DrawableInflater getDrawableInflater()
public ConfigurationBoundResourceCache<Animator> getAnimatorCache()
public ConfigurationBoundResourceCache<StateListAnimator> getStateListAnimatorCache()
public CharSequence getText(@StringRes int id) throws Resources.NotFoundException
id
- The desired resource identifier, as generated by the aapt
tool. This integer encodes the package, type, and resource
entry. The value 0 is an invalid identifier.Resources.NotFoundException
- Throws NotFoundException if the given ID does not exist.public CharSequence getQuantityText(@PluralsRes int id, int quantity) throws Resources.NotFoundException
id
- The desired resource identifier, as generated by the aapt
tool. This integer encodes the package, type, and resource
entry. The value 0 is an invalid identifier.quantity
- The number used to get the correct string for the current language's
plural rules.Resources.NotFoundException
- Throws NotFoundException if the given ID does not exist.public String getString(@StringRes int id) throws Resources.NotFoundException
id
- The desired resource identifier, as generated by the aapt
tool. This integer encodes the package, type, and resource
entry. The value 0 is an invalid identifier.Resources.NotFoundException
- Throws NotFoundException if the given ID does not exist.public String getString(@StringRes int id, Object... formatArgs) throws Resources.NotFoundException
Formatter
and String.format(java.lang.String, java.lang.Object...)
. It will be stripped of any styled text
information.
id
- The desired resource identifier, as generated by the aapt
tool. This integer encodes the package, type, and resource
entry. The value 0 is an invalid identifier.formatArgs
- The format arguments that will be used for substitution.Resources.NotFoundException
- Throws NotFoundException if the given ID does not exist.public String getQuantityString(@PluralsRes int id, int quantity, Object... formatArgs) throws Resources.NotFoundException
Substitution of format arguments works as if using
Formatter
and String.format(java.lang.String, java.lang.Object...)
.
The resulting string will be stripped of any styled text information.
id
- The desired resource identifier, as generated by the aapt
tool. This integer encodes the package, type, and resource
entry. The value 0 is an invalid identifier.quantity
- The number used to get the correct string for the current language's
plural rules.formatArgs
- The format arguments that will be used for substitution.Resources.NotFoundException
- Throws NotFoundException if the given ID does not exist.public String getQuantityString(@PluralsRes int id, int quantity) throws Resources.NotFoundException
id
- The desired resource identifier, as generated by the aapt
tool. This integer encodes the package, type, and resource
entry. The value 0 is an invalid identifier.quantity
- The number used to get the correct string for the current language's
plural rules.Resources.NotFoundException
- Throws NotFoundException if the given ID does not exist.public CharSequence getText(@StringRes int id, CharSequence def)
id
- The desired resource identifier, as generated by the aapt
tool. This integer encodes the package, type, and resource
entry. The value 0 is an invalid identifier.def
- The default CharSequence to return.public CharSequence[] getTextArray(@ArrayRes int id) throws Resources.NotFoundException
id
- The desired resource identifier, as generated by the aapt
tool. This integer encodes the package, type, and resource
entry. The value 0 is an invalid identifier.Resources.NotFoundException
- Throws NotFoundException if the given ID does not exist.public String[] getStringArray(@ArrayRes int id) throws Resources.NotFoundException
id
- The desired resource identifier, as generated by the aapt
tool. This integer encodes the package, type, and resource
entry. The value 0 is an invalid identifier.Resources.NotFoundException
- Throws NotFoundException if the given ID does not exist.public int[] getIntArray(@ArrayRes int id) throws Resources.NotFoundException
id
- The desired resource identifier, as generated by the aapt
tool. This integer encodes the package, type, and resource
entry. The value 0 is an invalid identifier.Resources.NotFoundException
- Throws NotFoundException if the given ID does not exist.public TypedArray obtainTypedArray(@ArrayRes int id) throws Resources.NotFoundException
id
- The desired resource identifier, as generated by the aapt
tool. This integer encodes the package, type, and resource
entry. The value 0 is an invalid identifier.TypedArray.recycle()
when done with it.Resources.NotFoundException
- Throws NotFoundException if the given ID does not exist.public float getDimension(@DimenRes int id) throws Resources.NotFoundException
DisplayMetrics
associated
with the resources.id
- The desired resource identifier, as generated by the aapt
tool. This integer encodes the package, type, and resource
entry. The value 0 is an invalid identifier.Resources.NotFoundException
- Throws NotFoundException if the given ID does not exist.getDimensionPixelOffset(int)
,
getDimensionPixelSize(int)
public int getDimensionPixelOffset(@DimenRes int id) throws Resources.NotFoundException
getDimension(int)
, except the returned value is converted to
integer pixels for you. An offset conversion involves simply
truncating the base value to an integer.id
- The desired resource identifier, as generated by the aapt
tool. This integer encodes the package, type, and resource
entry. The value 0 is an invalid identifier.Resources.NotFoundException
- Throws NotFoundException if the given ID does not exist.getDimension(int)
,
getDimensionPixelSize(int)
public int getDimensionPixelSize(@DimenRes int id) throws Resources.NotFoundException
getDimension(int)
, except the returned value is converted to
integer pixels for use as a size. A size conversion involves
rounding the base value, and ensuring that a non-zero base value
is at least one pixel in size.id
- The desired resource identifier, as generated by the aapt
tool. This integer encodes the package, type, and resource
entry. The value 0 is an invalid identifier.Resources.NotFoundException
- Throws NotFoundException if the given ID does not exist.getDimension(int)
,
getDimensionPixelOffset(int)
public float getFraction(@FractionRes int id, int base, int pbase)
id
- The desired resource identifier, as generated by the aapt
tool. This integer encodes the package, type, and resource
entry. The value 0 is an invalid identifier.base
- The base value of this fraction. In other words, a
standard fraction is multiplied by this value.pbase
- The parent base value of this fraction. In other
words, a parent fraction (nn%p) is multiplied by this
value.Resources.NotFoundException
- Throws NotFoundException if the given ID does not exist.@Deprecated public Drawable getDrawable(@DrawableRes int id) throws Resources.NotFoundException
getDrawable(int, Theme)
instead.Note: Prior to
Build.VERSION_CODES.JELLY_BEAN
, this function
would not correctly retrieve the final configuration density when
the resource ID passed here is an alias to another Drawable resource.
This means that if the density configuration of the alias resource
is different than the actual resource, the density of the returned
Drawable would be incorrect, resulting in bad scaling. To work
around this, you can instead manually resolve the aliased reference
by using getValue(int, TypedValue, boolean)
and passing
true
for resolveRefs
. The resulting
TypedValue.resourceId
value may be passed to this method.
Note: To obtain a themed drawable, use
Context.getDrawable(int)
or getDrawable(int, Theme)
passing the desired theme.
id
- The desired resource identifier, as generated by the aapt
tool. This integer encodes the package, type, and resource
entry. The value 0 is an invalid identifier.Resources.NotFoundException
- Throws NotFoundException if the given ID does
not exist.getDrawable(int, Theme)
public Drawable getDrawable(@DrawableRes int id, Resources.Theme theme) throws Resources.NotFoundException
id
- The desired resource identifier, as generated by the aapt
tool. This integer encodes the package, type, and resource
entry. The value 0 is an invalid identifier.theme
- The theme used to style the drawable attributes, may be null
.Resources.NotFoundException
- Throws NotFoundException if the given ID does
not exist.@Deprecated public Drawable getDrawableForDensity(@DrawableRes int id, int density) throws Resources.NotFoundException
getDrawableForDensity(int, int, Theme)
instead.Note: To obtain a themed drawable, use
Context.getDrawable(int)
or getDrawableForDensity(int, int, Theme)
passing the desired
theme.
id
- The desired resource identifier, as generated by the aapt tool.
This integer encodes the package, type, and resource entry.
The value 0 is an invalid identifier.density
- the desired screen density indicated by the resource as
found in DisplayMetrics
.Resources.NotFoundException
- Throws NotFoundException if the given ID does
not exist.getDrawableForDensity(int, int, Theme)
public Drawable getDrawableForDensity(@DrawableRes int id, int density, Resources.Theme theme)
id
- The desired resource identifier, as generated by the aapt tool.
This integer encodes the package, type, and resource entry.
The value 0 is an invalid identifier.density
- The desired screen density indicated by the resource as
found in DisplayMetrics
.theme
- The theme used to style the drawable attributes, may be null
.Resources.NotFoundException
- Throws NotFoundException if the given ID does
not exist.public Movie getMovie(@RawRes int id) throws Resources.NotFoundException
id
- The desired resource identifier, as generated by the aapt
tool. This integer encodes the package, type, and resource
entry. The value 0 is an invalid identifier.Resources.NotFoundException
- Throws NotFoundException if the given ID does not exist.@Deprecated public int getColor(@ColorRes int id) throws Resources.NotFoundException
getColor(int, Theme)
instead.ColorStateList
, then the default color
from the set is returned.id
- The desired resource identifier, as generated by the aapt
tool. This integer encodes the package, type, and resource
entry. The value 0 is an invalid identifier.Resources.NotFoundException
- Throws NotFoundException if the given ID does
not exist.public int getColor(@ColorRes int id, Resources.Theme theme) throws Resources.NotFoundException
ColorStateList
, then the default
color from the set is returned.id
- The desired resource identifier, as generated by the aapt
tool. This integer encodes the package, type, and resource
entry. The value 0 is an invalid identifier.theme
- The theme used to style the color attributes, may be
null
.Resources.NotFoundException
- Throws NotFoundException if the given ID does
not exist.@Deprecated public ColorStateList getColorStateList(@ColorRes int id) throws Resources.NotFoundException
getColorStateList(int, Theme)
instead.ColorStateList
holding multiple possible colors.id
- The desired resource identifier of a ColorStateList
,
as generated by the aapt tool. This integer encodes the
package, type, and resource entry. The value 0 is an invalid
identifier.Resources.NotFoundException
- Throws NotFoundException if the given ID does
not exist.public ColorStateList getColorStateList(@ColorRes int id, Resources.Theme theme) throws Resources.NotFoundException
ColorStateList
holding multiple possible colors.id
- The desired resource identifier of a ColorStateList
,
as generated by the aapt tool. This integer encodes the
package, type, and resource entry. The value 0 is an invalid
identifier.theme
- The theme used to style the color attributes, may be
null
.Resources.NotFoundException
- Throws NotFoundException if the given ID does
not exist.public ComplexColor loadComplexColor(TypedValue value, int id, Resources.Theme theme)
public boolean getBoolean(@BoolRes int id) throws Resources.NotFoundException
id
- The desired resource identifier, as generated by the aapt
tool. This integer encodes the package, type, and resource
entry. The value 0 is an invalid identifier.Resources.NotFoundException
- Throws NotFoundException if the given ID does not exist.public int getInteger(@IntegerRes int id) throws Resources.NotFoundException
id
- The desired resource identifier, as generated by the aapt
tool. This integer encodes the package, type, and resource
entry. The value 0 is an invalid identifier.Resources.NotFoundException
- Throws NotFoundException if the given ID does not exist.public float getFloat(int id)
id
- The desired resource identifier, as generated by the aapt
tool. This integer encodes the package, type, and resource
entry. The value 0 is an invalid identifier.Resources.NotFoundException
- Throws NotFoundException if the given ID does
not exist or is not a floating-point value.public XmlResourceParser getLayout(@LayoutRes int id) throws Resources.NotFoundException
This function is really a simple wrapper for calling
getXml(int)
with a layout resource.
id
- The desired resource identifier, as generated by the aapt
tool. This integer encodes the package, type, and resource
entry. The value 0 is an invalid identifier.Resources.NotFoundException
- Throws NotFoundException if the given ID does not exist.getXml(int)
public XmlResourceParser getAnimation(@AnimRes int id) throws Resources.NotFoundException
This function is really a simple wrapper for calling
getXml(int)
with an animation resource.
id
- The desired resource identifier, as generated by the aapt
tool. This integer encodes the package, type, and resource
entry. The value 0 is an invalid identifier.Resources.NotFoundException
- Throws NotFoundException if the given ID does not exist.getXml(int)
public XmlResourceParser getXml(@XmlRes int id) throws Resources.NotFoundException
The XmlPullParser implementation returned here has some limited functionality. In particular, you can't change its input, and only high-level parsing events are available (since the document was pre-parsed for you at build time, which involved merging text and stripping comments).
id
- The desired resource identifier, as generated by the aapt
tool. This integer encodes the package, type, and resource
entry. The value 0 is an invalid identifier.Resources.NotFoundException
- Throws NotFoundException if the given ID does not exist.AttributeSet
public InputStream openRawResource(@RawRes int id) throws Resources.NotFoundException
id
- The resource identifier to open, as generated by the appt
tool.Resources.NotFoundException
- Throws NotFoundException if the given ID does not exist.public InputStream openRawResource(@RawRes int id, TypedValue value) throws Resources.NotFoundException
id
- The resource identifier to open, as generated by the appt tool.value
- The TypedValue object to hold the resource information.Resources.NotFoundException
- Throws NotFoundException if the given ID does not exist.public AssetFileDescriptor openRawResourceFd(@RawRes int id) throws Resources.NotFoundException
This function only works for resources that are stored in the package as uncompressed data, which typically includes things like mp3 files and png images.
id
- The resource identifier to open, as generated by the appt
tool.Resources.NotFoundException
- Throws NotFoundException if the given ID does not exist.public void getValue(@AnyRes int id, TypedValue outValue, boolean resolveRefs) throws Resources.NotFoundException
id
- The desired resource identifier, as generated by the aapt
tool. This integer encodes the package, type, and resource
entry. The value 0 is an invalid identifier.outValue
- Object in which to place the resource data.resolveRefs
- If true, a resource that is a reference to another
resource will be followed so that you receive the
actual final resource data. If false, the TypedValue
will be filled in with the reference itself.Resources.NotFoundException
- Throws NotFoundException if the given ID does not exist.public void getValueForDensity(@AnyRes int id, int density, TypedValue outValue, boolean resolveRefs) throws Resources.NotFoundException
id
- resource identifierdensity
- density in DPIresolveRefs
- If true, a resource that is a reference to another
resource will be followed so that you receive the actual final
resource data. If false, the TypedValue will be filled in with
the reference itself.Resources.NotFoundException
- Throws NotFoundException if the given ID does
not exist.getValue(String, TypedValue, boolean)
public void getValue(String name, TypedValue outValue, boolean resolveRefs) throws Resources.NotFoundException
Note: use of this function is discouraged. It is much more efficient to retrieve resources by identifier than by name.
name
- The name of the desired resource. This is passed to
getIdentifier() with a default type of "string".outValue
- Object in which to place the resource data.resolveRefs
- If true, a resource that is a reference to another
resource will be followed so that you receive the
actual final resource data. If false, the TypedValue
will be filled in with the reference itself.Resources.NotFoundException
- Throws NotFoundException if the given ID does not exist.public final Resources.Theme newTheme()
public TypedArray obtainAttributes(AttributeSet set, int[] attrs)
set
- The current attribute values to retrieve.attrs
- The specific attributes to be retrieved.TypedArray.recycle()
when done with it.Resources.Theme.obtainStyledAttributes(AttributeSet, int[], int, int)
@Deprecated public void updateConfiguration(Configuration config, DisplayMetrics metrics)
Context.createConfigurationContext(Configuration)
.public void updateConfiguration(Configuration config, DisplayMetrics metrics, CompatibilityInfo compat)
public static void updateSystemConfiguration(Configuration config, DisplayMetrics metrics, CompatibilityInfo compat)
public DisplayMetrics getDisplayMetrics()
public DisplayAdjustments getDisplayAdjustments()
public Configuration getConfiguration()
public Configuration[] getSizeConfigurations()
public CompatibilityInfo getCompatibilityInfo()
public void setCompatibilityInfo(CompatibilityInfo ci)
public int getIdentifier(String name, String defType, String defPackage)
Note: use of this function is discouraged. It is much more efficient to retrieve resources by identifier than by name.
name
- The name of the desired resource.defType
- Optional default resource type to find, if "type/" is
not included in the name. Can be null to require an
explicit type.defPackage
- Optional default package to find, if "package:" is
not included in the name. Can be null to require an
explicit package.public static boolean resourceHasPackage(@AnyRes int resid)
public String getResourceName(@AnyRes int resid) throws Resources.NotFoundException
resid
- The resource identifier whose name is to be retrieved.Resources.NotFoundException
- Throws NotFoundException if the given ID does not exist.getResourcePackageName(int)
,
getResourceTypeName(int)
,
getResourceEntryName(int)
public String getResourcePackageName(@AnyRes int resid) throws Resources.NotFoundException
resid
- The resource identifier whose package name is to be
retrieved.Resources.NotFoundException
- Throws NotFoundException if the given ID does not exist.getResourceName(int)
public String getResourceTypeName(@AnyRes int resid) throws Resources.NotFoundException
resid
- The resource identifier whose type name is to be
retrieved.Resources.NotFoundException
- Throws NotFoundException if the given ID does not exist.getResourceName(int)
public String getResourceEntryName(@AnyRes int resid) throws Resources.NotFoundException
resid
- The resource identifier whose entry name is to be
retrieved.Resources.NotFoundException
- Throws NotFoundException if the given ID does not exist.getResourceName(int)
public void parseBundleExtras(XmlResourceParser parser, Bundle outBundle) throws XmlPullParserException, IOException
<extra>
tags from
an XML file. You call this when you are at the parent tag of the
extra tags, and it will return once all of the child tags have been parsed.
This will call parseBundleExtra(java.lang.String, android.util.AttributeSet, android.os.Bundle)
for each extra tag encountered.parser
- The parser from which to retrieve the extras.outBundle
- A Bundle in which to place all parsed extras.XmlPullParserException
IOException
public void parseBundleExtra(String tagName, AttributeSet attrs, Bundle outBundle) throws XmlPullParserException
android.R.styleable#Extra
. The following value types are supported:
tagName
- The name of the tag these attributes come from; this is
only used for reporting error messages.attrs
- The attributes from which to retrieve the name/value pair.outBundle
- The Bundle in which to place the parsed value.XmlPullParserException
- If the attributes are not valid.public final AssetManager getAssets()
public final void flushLayoutCache()
public final void startPreloading()
public final void finishPreloading()
public LongSparseArray<Drawable.ConstantState> getPreloadedDrawables()
public int calcConfigChanges(Configuration config)
public static TypedArray obtainAttributes(Resources res, Resources.Theme theme, AttributeSet set, int[] attrs)