Stay organized with collections
Save and categorize content based on your preferences.
HarmonizedColors
public
class
HarmonizedColors
extends Object
java.lang.Object
|
↳ |
com.google.android.material.color.HarmonizedColors
|
A class for harmonizing color resources and attributes.
This class is used for harmonizing color resources/attributes defined in xml at runtime. The
values of harmonized resources/attributes will be overridden, and afterwards if you retrieve the
value from the associated context, or inflate resources like layouts that are using those
harmonized resources/attributes, the overridden values will be used instead.
If you need to harmonize color resources at runtime, see:
applyToContextIfAvailable(Context, HarmonizedColorsOptions)
, and
wrapContextIfAvailable(Context, HarmonizedColorsOptions)
Summary
Inherited methods |
From class
java.lang.Object
Object
|
clone()
|
boolean
|
equals(Object arg0)
|
void
|
finalize()
|
final
Class<?>
|
getClass()
|
int
|
hashCode()
|
final
void
|
notify()
|
final
void
|
notifyAll()
|
String
|
toString()
|
final
void
|
wait(long arg0, int arg1)
|
final
void
|
wait(long arg0)
|
final
void
|
wait()
|
|
Public methods
applyToContextIfAvailable
public static void applyToContextIfAvailable (Context context,
HarmonizedColorsOptions options)
Harmonizes the specified color resources, attributes, and theme overlay in the Context
provided.
If harmonization is not available, provided color resources and attributes in HarmonizedColorsOptions
will not be harmonized.
Parameters |
context |
Context : The target context. |
options |
HarmonizedColorsOptions : The HarmonizedColorsOptions object that specifies the resource ids,
color attributes to be harmonized and the color attribute to harmonize with.
|
isHarmonizedColorAvailable
public static boolean isHarmonizedColorAvailable ()
If harmonization is not available, color will not be harmonized.
Returns |
boolean |
true if harmonized colors are available on the current SDK level, otherwise
false will be returned.
|
wrapContextIfAvailable
public static Context wrapContextIfAvailable (Context context,
HarmonizedColorsOptions options)
Wraps the given Context from HarmonizedColorsOptions with the color resources being harmonized.
If harmonization is not available, provided color resources and attributes in HarmonizedColorsOptions
will not be harmonized.
Parameters |
context |
Context : The target context. |
options |
HarmonizedColorsOptions : The HarmonizedColorsOptions object that specifies the resource ids,
color attributes to be harmonized and the color attribute to harmonize with. |
Returns |
Context |
the new context with resources being harmonized. If resources are not harmonized
successfully, the context passed in will be returned.
|
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-02-10 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-02-10 UTC."],[],[],null,["# HarmonizedColors\n\nSummary: [Methods](#pubmethods) \\| [Inherited Methods](#inhmethods) \n\nHarmonizedColors\n================\n\n\n`\npublic\n\n\nclass\nHarmonizedColors\n`\n\n\n`\n\nextends Object\n\n\n`\n\n`\n\n\n`\n\n|---|----------------------------------------------------|\n| java.lang.Object ||\n| ↳ | com.google.android.material.color.HarmonizedColors |\n\n\u003cbr /\u003e\n\n*** ** * ** ***\n\nA class for harmonizing color resources and attributes.\n\nThis class is used for harmonizing color resources/attributes defined in xml at runtime. The\nvalues of harmonized resources/attributes will be overridden, and afterwards if you retrieve the\nvalue from the associated context, or inflate resources like layouts that are using those\nharmonized resources/attributes, the overridden values will be used instead.\n\nIf you need to harmonize color resources at runtime, see:\n[applyToContextIfAvailable(Context, HarmonizedColorsOptions)](/reference/com/google/android/material/color/HarmonizedColors#applyToContextIfAvailable(android.content.Context,%20com.google.android.material.color.HarmonizedColorsOptions)), and\n[wrapContextIfAvailable(Context, HarmonizedColorsOptions)](/reference/com/google/android/material/color/HarmonizedColors#wrapContextIfAvailable(android.content.Context,%20com.google.android.material.color.HarmonizedColorsOptions))\n\nSummary\n-------\n\n| ### Public methods ||\n|-------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| ` static void` | ` `[applyToContextIfAvailable](/reference/com/google/android/material/color/HarmonizedColors#applyToContextIfAvailable(android.content.Context,%20com.google.android.material.color.HarmonizedColorsOptions))`(Context context, `[HarmonizedColorsOptions](/reference/com/google/android/material/color/HarmonizedColorsOptions)` options) ` Harmonizes the specified color resources, attributes, and theme overlay in the [Context](/reference/android/content/Context) provided. |\n| ` static boolean` | ` `[isHarmonizedColorAvailable](/reference/com/google/android/material/color/HarmonizedColors#isHarmonizedColorAvailable())`() ` \u003cbr /\u003e If harmonization is not available, color will not be harmonized. |\n| ` static Context` | ` `[wrapContextIfAvailable](/reference/com/google/android/material/color/HarmonizedColors#wrapContextIfAvailable(android.content.Context,%20com.google.android.material.color.HarmonizedColorsOptions))`(Context context, `[HarmonizedColorsOptions](/reference/com/google/android/material/color/HarmonizedColorsOptions)` options) ` Wraps the given Context from HarmonizedColorsOptions with the color resources being harmonized. |\n\n| ### Inherited methods |\n|-----------------------|---|\n| From class ` java.lang.Object ` |-------------------|-------------------------------| | ` Object` | ` clone() ` | | ` boolean` | ` equals(Object arg0) ` | | ` void` | ` finalize() ` | | ` final Class\u003c?\u003e` | ` getClass() ` | | ` int` | ` hashCode() ` | | ` final void` | ` notify() ` | | ` final void` | ` notifyAll() ` | | ` String` | ` toString() ` | | ` final void` | ` wait(long arg0, int arg1) ` | | ` final void` | ` wait(long arg0) ` | | ` final void` | ` wait() ` | ||\n\nPublic methods\n--------------\n\n### applyToContextIfAvailable\n\n```\npublic static void applyToContextIfAvailable (Context context, \n HarmonizedColorsOptions options)\n```\n\nHarmonizes the specified color resources, attributes, and theme overlay in the [Context](/reference/android/content/Context) provided.\n\nIf harmonization is not available, provided color resources and attributes in [HarmonizedColorsOptions](/reference/com/google/android/material/color/HarmonizedColorsOptions) will not be harmonized.\n\n\u003cbr /\u003e\n\n| Parameters ||\n|-----------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `context` | `Context`: The target context. \u003cbr /\u003e |\n| `options` | `HarmonizedColorsOptions`: The [HarmonizedColorsOptions](/reference/com/google/android/material/color/HarmonizedColorsOptions) object that specifies the resource ids, color attributes to be harmonized and the color attribute to harmonize with. \u003cbr /\u003e |\n\n### isHarmonizedColorAvailable\n\n```\npublic static boolean isHarmonizedColorAvailable ()\n```\n\n\u003cbr /\u003e\n\nIf harmonization is not available, color will not be harmonized.\n\n\u003cbr /\u003e\n\n| Returns ||\n|-----------|----------------------------------------------------------------------------------------------------------------|\n| `boolean` | `true` if harmonized colors are available on the current SDK level, otherwise `false` will be returned. \u003cbr /\u003e |\n\n**See also:**\n\n- [applyToContextIfAvailable(Context, HarmonizedColorsOptions)](/reference/com/google/android/material/color/HarmonizedColors#applyToContextIfAvailable(android.content.Context,%20com.google.android.material.color.HarmonizedColorsOptions))\n- [wrapContextIfAvailable(Context, HarmonizedColorsOptions)](/reference/com/google/android/material/color/HarmonizedColors#wrapContextIfAvailable(android.content.Context,%20com.google.android.material.color.HarmonizedColorsOptions)) \n\n### wrapContextIfAvailable\n\n```\npublic static Context wrapContextIfAvailable (Context context, \n HarmonizedColorsOptions options)\n```\n\nWraps the given Context from HarmonizedColorsOptions with the color resources being harmonized.\n\nIf harmonization is not available, provided color resources and attributes in [HarmonizedColorsOptions](/reference/com/google/android/material/color/HarmonizedColorsOptions) will not be harmonized.\n\n\u003cbr /\u003e\n\n| Parameters ||\n|-----------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `context` | `Context`: The target context. \u003cbr /\u003e |\n| `options` | `HarmonizedColorsOptions`: The [HarmonizedColorsOptions](/reference/com/google/android/material/color/HarmonizedColorsOptions) object that specifies the resource ids, color attributes to be harmonized and the color attribute to harmonize with. \u003cbr /\u003e |\n\n| Returns ||\n|-----------|-----------------------------------------------------------------------------------------------------------------------------------------------|\n| `Context` | the new context with resources being harmonized. If resources are not harmonized successfully, the context passed in will be returned. \u003cbr /\u003e |"]]