diff options
author | Alan Viverette <alanv@google.com> | 2015-01-06 18:47:25 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2015-01-06 18:47:29 +0000 |
commit | 304ea5aac77cae03b4e8440a7c73c18086d96a20 (patch) | |
tree | 6411b0eb6ee19f4334988bee2f13e6c3712ed864 /core/java/android/content/Context.java | |
parent | 2b2ad7ce9f008cc383394cc91389d667575ec45d (diff) | |
parent | 45c4bbbbce6bbad50a033efcba7948a23f1f117a (diff) | |
download | frameworks_base-304ea5aac77cae03b4e8440a7c73c18086d96a20.zip frameworks_base-304ea5aac77cae03b4e8440a7c73c18086d96a20.tar.gz frameworks_base-304ea5aac77cae03b4e8440a7c73c18086d96a20.tar.bz2 |
Merge "Allow use of theme attributes in color state lists"
Diffstat (limited to 'core/java/android/content/Context.java')
-rw-r--r-- | core/java/android/content/Context.java | 42 |
1 files changed, 40 insertions, 2 deletions
diff --git a/core/java/android/content/Context.java b/core/java/android/content/Context.java index b329e1f..dec2524 100644 --- a/core/java/android/content/Context.java +++ b/core/java/android/content/Context.java @@ -24,6 +24,7 @@ import android.annotation.SystemApi; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.content.res.AssetManager; +import android.content.res.ColorStateList; import android.content.res.Configuration; import android.content.res.Resources; import android.content.res.TypedArray; @@ -392,18 +393,55 @@ public abstract class Context { } /** - * Return a drawable object associated with a particular resource ID and + * Returns a color associated with a particular resource ID and styled for + * the current theme. + * + * @param 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. + * @return A single color value in the form 0xAARRGGBB. + * @throws android.content.res.Resources.NotFoundException if the given ID + * does not exist. + */ + @Nullable + public final int getColor(int id) { + return getResources().getColor(id, getTheme()); + } + + /** + * Returns a drawable object associated with a particular resource ID and * styled for the current theme. * * @param 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. - * @return Drawable An object that can be used to draw this resource. + * @return An object that can be used to draw this resource, or + * {@code null} if the resource could not be resolved. + * @throws android.content.res.Resources.NotFoundException if the given ID + * does not exist. */ + @Nullable public final Drawable getDrawable(int id) { return getResources().getDrawable(id, getTheme()); } + /** + * Returns a color state list associated with a particular resource ID and + * styled for the current theme. + * + * @param 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. + * @return A color state list, or {@code null} if the resource could not be + * resolved. + * @throws android.content.res.Resources.NotFoundException if the given ID + * does not exist. + */ + @Nullable + public final ColorStateList getColorStateList(int id) { + return getResources().getColorStateList(id, getTheme()); + } + /** * Set the base theme for this context. Note that this should be called * before any views are instantiated in the Context (for example before |