public final class Resources.Theme extends Object
TypedArray
to resolve the final value for an attribute.
The Theme's attributes come into play in two ways: (1) a styled attribute can explicit reference a value in the theme through the "?themeAttribute" syntax; (2) if no value has been defined for a particular styled attribute, as a last resort we will try to find that attribute's value in the Theme.
You will normally use the obtainStyledAttributes(int[])
APIs to
retrieve XML attributes with style and theme information applied.
Modifier and Type | Method and Description |
---|---|
void |
applyStyle(int resId,
boolean force)
Place new attribute values into the theme.
|
void |
dump(int priority,
String tag,
String prefix)
Print contents of this theme out to the log.
|
void |
encode(ViewHierarchyEncoder encoder) |
int[] |
getAllAttributes()
Gets all of the attribute ids associated with this
Resources.Theme . |
int |
getChangingConfigurations()
Returns a bit mask of configuration changes that will impact this
theme (and thus require completely reloading it).
|
Drawable |
getDrawable(int id)
Return a drawable object associated with a particular resource ID
and styled for the Theme.
|
android.content.res.Resources.ThemeKey |
getKey() |
Resources |
getResources()
Returns the resources to which this theme belongs.
|
String[] |
getTheme()
Parses
getKey() and returns a String array that holds pairs of
adjacent Theme data: resource name followed by whether or not it was
forced, as specified by applyStyle(int, boolean) . |
TypedArray |
obtainStyledAttributes(AttributeSet set,
int[] attrs,
int defStyleAttr,
int defStyleRes)
Return a TypedArray holding the attribute values in
set
that are listed in attrs.
|
TypedArray |
obtainStyledAttributes(int[] attrs)
Return a TypedArray holding the values defined by
Theme which are listed in attrs.
|
TypedArray |
obtainStyledAttributes(int resId,
int[] attrs)
Return a TypedArray holding the values defined by the style
resource resid which are listed in attrs.
|
void |
rebase()
Rebases the theme against the parent Resource object's current
configuration by re-applying the styles passed to
applyStyle(int, boolean) . |
boolean |
resolveAttribute(int resid,
TypedValue outValue,
boolean resolveRefs)
Retrieve the value of an attribute in the Theme.
|
TypedArray |
resolveAttributes(int[] values,
int[] attrs)
Retrieve the values for a set of attributes in the Theme.
|
void |
setTo(Resources.Theme other)
Set this theme to hold the same contents as the theme
other.
|
public void applyStyle(int resId, boolean force)
The semantics of this function depends on the force argument: If false, only values that are not already defined in the theme will be copied from the system resource; otherwise, if any of the style's attributes are already defined in the theme, the current values in the theme will be overwritten.
resId
- The resource ID of a style resource from which to
obtain attribute values.force
- If true, values in the style resource will always be
used in the theme; otherwise, they will only be used
if not already defined in the theme.public void setTo(Resources.Theme other)
other
- The existing Theme to copy from.public TypedArray obtainStyledAttributes(@StyleableRes int[] attrs)
Be sure to call TypedArray.recycle()
when you are done
with the array.
attrs
- The desired attributes.TypedArray.recycle()
when done with it.Resources.NotFoundException
- Throws NotFoundException if the given ID does not exist.Resources.obtainAttributes(android.util.AttributeSet, int[])
,
obtainStyledAttributes(int, int[])
,
obtainStyledAttributes(AttributeSet, int[], int, int)
public TypedArray obtainStyledAttributes(@StyleRes int resId, @StyleableRes int[] attrs) throws Resources.NotFoundException
Be sure to call TypedArray.recycle()
when you are done
with the array.
resId
- The desired style resource.attrs
- The desired attributes in the style.TypedArray.recycle()
when done with it.Resources.NotFoundException
- Throws NotFoundException if the given ID does not exist.Resources.obtainAttributes(android.util.AttributeSet, int[])
,
obtainStyledAttributes(int[])
,
obtainStyledAttributes(AttributeSet, int[], int, int)
public TypedArray obtainStyledAttributes(AttributeSet set, @StyleableRes int[] attrs, @AttrRes int defStyleAttr, @StyleRes int defStyleRes)
Be sure to call TypedArray.recycle()
when you are done
with the array.
When determining the final value of a particular attribute, there are four inputs that come into play:
Each of these inputs is considered in-order, with the first listed
taking precedence over the following ones. In other words, if in the
AttributeSet you have supplied <Button
textColor="#ff000000">
, then the button's text will
always be black, regardless of what is specified in any of
the styles.
set
- The base set of attribute values. May be null.attrs
- The desired attributes to be retrieved.defStyleAttr
- An attribute in the current theme that contains a
reference to a style resource that supplies
defaults values for the TypedArray. Can be
0 to not look for defaults.defStyleRes
- A resource identifier of a style resource that
supplies default values for the TypedArray,
used only if defStyleAttr is 0 or can not be found
in the theme. Can be 0 to not look for defaults.TypedArray.recycle()
when done with it.Resources.obtainAttributes(android.util.AttributeSet, int[])
,
obtainStyledAttributes(int[])
,
obtainStyledAttributes(int, int[])
public TypedArray resolveAttributes(int[] values, int[] attrs)
Resources.getValue(int, android.util.TypedValue, boolean)
.values
- The base set of attribute values, must be equal in
length to attrs
. All values must be of type
TypedValue.TYPE_ATTRIBUTE
.attrs
- The desired attributes to be retrieved.TypedArray.recycle()
when done with it.public boolean resolveAttribute(int resid, TypedValue outValue, boolean resolveRefs)
Resources.getValue(int, android.util.TypedValue, boolean)
.resid
- The resource identifier of the desired theme
attribute.outValue
- Filled in with the ultimate resource value supplied
by the attribute.resolveRefs
- If true, resource references will be walked; if
false, outValue may be a
TYPE_REFERENCE. In either case, it will never
be a TYPE_ATTRIBUTE.public int[] getAllAttributes()
Resources.Theme
. For debugging only.Resources.Theme
.public Resources getResources()
public Drawable getDrawable(@DrawableRes 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 getChangingConfigurations()
ActivityInfo
ActivityInfo
public void dump(int priority, String tag, String prefix)
priority
- The log priority to use.tag
- The log tag to use.prefix
- Text to prefix each line printed.public android.content.res.Resources.ThemeKey getKey()
public String[] getTheme()
getKey()
and returns a String array that holds pairs of
adjacent Theme data: resource name followed by whether or not it was
forced, as specified by applyStyle(int, boolean)
.public void encode(ViewHierarchyEncoder encoder)
public void rebase()
applyStyle(int, boolean)
.