diff options
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 015e1ec..e484785 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 |