Stay organized with collections
Save and categorize content based on your preferences.
HarmonizedColorAttributes
public
final
class
HarmonizedColorAttributes
extends Object
java.lang.Object
|
↳ |
com.google.android.material.color.HarmonizedColorAttributes
|
A class for specifying color attributes for harmonization, which contains an array of color
attributes, with the option to specify a custom theme overlay.
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
create
public static HarmonizedColorAttributes create (int[] attributes,
int themeOverlay)
Create HarmonizedColorAttributes
with a theme overlay, along with an array of
attributes in the theme overlay.
In this method, instead of the color resource that the color attribute is pointing to in
the main theme/context being harmonized directly, the color resource in the theme overlay
context will be replaced with the harmonized color attribute instead.
Parameters |
attributes |
int |
themeOverlay |
int |
create
public static HarmonizedColorAttributes create (int[] attributes)
Create HarmonizedColorAttributes
with an array of color attributes. If this is
called, the resources pointed by the attributes will be resolved at runtime and harmonized.
If you're concerned about accidentally overwriting color resources, see
create(int[], int)
.
Parameters |
attributes |
int |
createMaterialDefaults
public static HarmonizedColorAttributes createMaterialDefaults ()
Create HarmonizedColorAttributes
with Material default, with Error colors being
harmonized.
Instead of directly overwriting the resources that `colorError`, `colorOnError`,
`colorErrorContainer` and `colorOnErrorContainer` points to in the main theme/context, we
would:
1. look up the resources values in the theme overlay `Context`.
2. retrieve the harmonized resources with Primary.
3. replace `@color/material_harmonized_color_error`,
`@color/material_harmonized_color_on_error`, etc. with the harmonized resources.
That way the Error roles in the theme overlay would point to harmonized resources.
getAttributes
public int[] getAttributes ()
Returns the array of color attributes for harmonization.
getThemeOverlay
public int getThemeOverlay ()
Returns the custom theme overlay for harmonization, default is 0 if not specified.
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,["# HarmonizedColorAttributes\n\nSummary: [Methods](#pubmethods) \\| [Inherited Methods](#inhmethods) \n\nHarmonizedColorAttributes\n=========================\n\n\n`\npublic\n\nfinal\n\nclass\nHarmonizedColorAttributes\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.HarmonizedColorAttributes |\n\n\u003cbr /\u003e\n\n*** ** * ** ***\n\nA class for specifying color attributes for harmonization, which contains an array of color\nattributes, with the option to specify a custom theme overlay.\n\nSummary\n-------\n\n| ### Public methods ||\n|---------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| ` static `[HarmonizedColorAttributes](/reference/com/google/android/material/color/HarmonizedColorAttributes) | ` `[create](/reference/com/google/android/material/color/HarmonizedColorAttributes#create(int[],%20int))`(int[] attributes, int themeOverlay) ` Create [HarmonizedColorAttributes](/reference/com/google/android/material/color/HarmonizedColorAttributes) with a theme overlay, along with an array of attributes in the theme overlay. |\n| ` static `[HarmonizedColorAttributes](/reference/com/google/android/material/color/HarmonizedColorAttributes) | ` `[create](/reference/com/google/android/material/color/HarmonizedColorAttributes#create(int[]))`(int[] attributes) ` Create [HarmonizedColorAttributes](/reference/com/google/android/material/color/HarmonizedColorAttributes) with an array of color attributes. |\n| ` static `[HarmonizedColorAttributes](/reference/com/google/android/material/color/HarmonizedColorAttributes) | ` `[createMaterialDefaults](/reference/com/google/android/material/color/HarmonizedColorAttributes#createMaterialDefaults())`() ` Create [HarmonizedColorAttributes](/reference/com/google/android/material/color/HarmonizedColorAttributes) with Material default, with Error colors being harmonized. |\n| ` int[]` | ` `[getAttributes](/reference/com/google/android/material/color/HarmonizedColorAttributes#getAttributes())`() ` Returns the array of color attributes for harmonization. |\n| ` int` | ` `[getThemeOverlay](/reference/com/google/android/material/color/HarmonizedColorAttributes#getThemeOverlay())`() ` Returns the custom theme overlay for harmonization, default is 0 if not specified. |\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### create\n\n```\npublic static HarmonizedColorAttributes create (int[] attributes, \n int themeOverlay)\n```\n\nCreate [HarmonizedColorAttributes](/reference/com/google/android/material/color/HarmonizedColorAttributes) with a theme overlay, along with an array of\nattributes in the theme overlay.\n\nIn this method, instead of the color resource that the color attribute is pointing to in\nthe main theme/context being harmonized directly, the color resource in the theme overlay\ncontext will be replaced with the harmonized color attribute instead.\n\n\u003cbr /\u003e\n\n| Parameters ||\n|----------------|--------------|\n| `attributes` | `int` \u003cbr /\u003e |\n| `themeOverlay` | `int` \u003cbr /\u003e |\n\n| Returns ||\n|-----------------------------------------------------------------------------------------------------|--------|\n| [HarmonizedColorAttributes](/reference/com/google/android/material/color/HarmonizedColorAttributes) | \u003cbr /\u003e |\n\n### create\n\n```\npublic static HarmonizedColorAttributes create (int[] attributes)\n```\n\nCreate [HarmonizedColorAttributes](/reference/com/google/android/material/color/HarmonizedColorAttributes) with an array of color attributes. If this is\ncalled, the resources pointed by the attributes will be resolved at runtime and harmonized.\nIf you're concerned about accidentally overwriting color resources, see\n[create(int[], int)](/reference/com/google/android/material/color/HarmonizedColorAttributes#create(int[],%20int)).\n\n\u003cbr /\u003e\n\n| Parameters ||\n|--------------|--------------|\n| `attributes` | `int` \u003cbr /\u003e |\n\n| Returns ||\n|-----------------------------------------------------------------------------------------------------|--------|\n| [HarmonizedColorAttributes](/reference/com/google/android/material/color/HarmonizedColorAttributes) | \u003cbr /\u003e |\n\n### createMaterialDefaults\n\n```\npublic static HarmonizedColorAttributes createMaterialDefaults ()\n```\n\nCreate [HarmonizedColorAttributes](/reference/com/google/android/material/color/HarmonizedColorAttributes) with Material default, with Error colors being\nharmonized.\n\nInstead of directly overwriting the resources that \\`colorError\\`, \\`colorOnError\\`,\n\\`colorErrorContainer\\` and \\`colorOnErrorContainer\\` points to in the main theme/context, we\nwould:\n\n\n1. look up the resources values in the theme overlay \\`Context\\`.\n2. retrieve the harmonized resources with Primary.\n3. replace \\`@color/material_harmonized_color_error\\`,\n\\`@color/material_harmonized_color_on_error\\`, etc. with the harmonized resources.\n\nThat way the Error roles in the theme overlay would point to harmonized resources.\n\n\u003cbr /\u003e\n\n| Returns ||\n|-----------------------------------------------------------------------------------------------------|--------|\n| [HarmonizedColorAttributes](/reference/com/google/android/material/color/HarmonizedColorAttributes) | \u003cbr /\u003e |\n\n### getAttributes\n\n```\npublic int[] getAttributes ()\n```\n\nReturns the array of color attributes for harmonization.\n\n\u003cbr /\u003e\n\n| Returns ||\n|---------|--------|\n| `int[]` | \u003cbr /\u003e |\n\n### getThemeOverlay\n\n```\npublic int getThemeOverlay ()\n```\n\nReturns the custom theme overlay for harmonization, default is 0 if not specified.\n\n\u003cbr /\u003e\n\n| Returns ||\n|-------|--------|\n| `int` | \u003cbr /\u003e |"]]