java.lang.Object | |
↳ | android.content.res.Resources.Theme |
This class holds the current attribute values for a particular theme.
In other words, a Theme is a set of values for resource attributes;
these are used in conjunction with 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(AttributeSet, int[], int, int)
APIs to
retrieve XML attributes with style and theme information applied.
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Place new attribute values into the theme.
| |||||||||||
Print contents of this theme out to the log.
| |||||||||||
Return a drawable object associated with a particular resource ID
and styled for the Theme.
| |||||||||||
Returns the resources to which this theme belongs.
| |||||||||||
Return a TypedArray holding the values defined by
Theme which are listed in attrs.
| |||||||||||
Return a TypedArray holding the values defined by the style
resource resid which are listed in attrs.
| |||||||||||
Return a TypedArray holding the attribute values in
set
that are listed in attrs.
| |||||||||||
Retrieve the value of an attribute in the Theme.
| |||||||||||
Set this theme to hold the same contents as the theme
other.
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Invoked when the garbage collector has detected that this instance is no longer reachable.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
|
Place new attribute values into the theme. The style resource specified by resid will be retrieved from this Theme's resources, its values placed into the Theme object.
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. |
Print contents of this theme out to the log. For debugging only.
priority | The log priority to use. |
---|---|
tag | The log tag to use. |
prefix | Text to prefix each line printed. |
Return a drawable object associated with a particular resource ID and styled for the 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. |
---|
Returns the resources to which this theme belongs.
Return a TypedArray holding the values defined by Theme which are listed in 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. |
---|
Return a TypedArray holding the values defined by the style resource resid which are listed in attrs.
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. |
---|
Return a TypedArray holding the attribute values in set that are listed in attrs. In addition, if the given AttributeSet specifies a style class (through the "style" attribute), that style will be applied on top of the base attributes it defines.
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.Retrieve the value of an attribute in the Theme. The contents of
outValue are ultimately filled in by
getValue(int, 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. |
Set this theme to hold the same contents as the theme other. If both of these themes are from the same Resources object, they will be identical after this function returns. If they are from different Resources, only the resources they have in common will be set in this theme.
other | The existing Theme to copy from. |
---|
Invoked when the garbage collector has detected that this instance is no longer reachable. The default implementation does nothing, but this method can be overridden to free resources.
Note that objects that override finalize
are significantly more expensive than
objects that don't. Finalizers may be run a long time after the object is no longer
reachable, depending on memory pressure, so it's a bad idea to rely on them for cleanup.
Note also that finalizers are run on a single VM-wide finalizer thread,
so doing blocking work in a finalizer is a bad idea. A finalizer is usually only necessary
for a class that has a native peer and needs to call a native method to destroy that peer.
Even then, it's better to provide an explicit close
method (and implement
Closeable
), and insist that callers manually dispose of instances. This
works well for something like files, but less well for something like a BigInteger
where typical calling code would have to deal with lots of temporaries. Unfortunately,
code that creates lots of temporaries is the worst kind of code from the point of view of
the single finalizer thread.
If you must use finalizers, consider at least providing your own
ReferenceQueue
and having your own thread process that queue.
Unlike constructors, finalizers are not automatically chained. You are responsible for
calling super.finalize()
yourself.
Uncaught exceptions thrown by finalizers are ignored and do not terminate the finalizer thread. See Effective Java Item 7, "Avoid finalizers" for more.
Throwable |
---|