Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 20 additions & 20 deletions docs/theming/Color.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ want to consider getting those tonal surface colors on the fly, by using the
convenient enums we provide in the Material Library. For example, if you want to
get the color hex value of Surface1, you can do:

```
```java
int colorSurface1 = SurfaceColors.SURFACE_1.getColor(context);
```

Expand Down Expand Up @@ -187,7 +187,7 @@ this helper class according to different scenarios:

In your application class’ `onCreate()` method, call:

```
```java
DynamicColors.applyToActivitiesIfAvailable(this);
```

Expand All @@ -202,7 +202,7 @@ If you are using Material 3 themes, `R.attr.dynamicColorThemeOverlay` will be
You can also have finer control over theme overlay deployment by providing a
precondition when calling the method:

```
```java
DynamicColors.applyToActivitiesIfAvailable(this, (activity, themeResId) -> {
// ...implement your own logic here. Return `true` if dynamic colors should be applied.
});
Expand All @@ -211,7 +211,7 @@ DynamicColors.applyToActivitiesIfAvailable(this, (activity, themeResId) -> {
Or provide your own customized dynamic color theme overlays, likely inheriting
from the Material3 theme overlays above, by doing:

```
``` java
DynamicColors.applyToActivitiesIfAvailable(this, R.style.ThemeOverlay_MyApp_DynamicColors_DayNight);
```

Expand All @@ -228,7 +228,7 @@ You can also opt to apply dynamic colors to a few specific activities, by
calling the following method in your activities’ `onCreate()` method (or before
you inflate anything from it):

```
```java
DynamicColors.applyToActivityIfAvailable(this);
```

Expand All @@ -246,7 +246,7 @@ precondition, to have finer control over theme overlay deployment. You may also
optionally specify an `OnAppliedCallback` function, which will be called after
dynamic colors have been applied:

```
```java
DynamicColorsOptions dynamicColorOptions =
new DynamicColorsOptions.Builder()
.setThemeOverlay(themeOverlay)
Expand All @@ -261,7 +261,7 @@ DynamicColors.applyToActivitiesIfAvailable(application, dynamicColorOptions);
You can also apply dynamic colors to a specific activity in the app by passing
in the specific activity and a `DynamicColorsOptions` object:

```
```java
DynamicColorsOptions dynamicColorOptions =
new DynamicColorsOptions.Builder()
.setThemeOverlay(themeOverlay)
Expand All @@ -277,7 +277,7 @@ Applying dynamic colors to a few of the views in an activity is more complex.
The easiest solution is to create a themed context to create the view. We
provide a helper method for this purpose:

```
```java
context = DynamicColors.wrapContextIfAvailable(context);
```

Expand Down Expand Up @@ -403,7 +403,7 @@ package:

In your application class or activity/fragment/view, call:

```
```java
int harmonizedColor = MaterialColors.harmonizeWithPrimary(context, colorToHarmonize);
```

Expand All @@ -424,7 +424,7 @@ construct a `HarmonizedColorsOptions`. You can optionally pass in an array of
resource ids for the color resources you'd like to harmonize, a
`HarmonizedColorAttributes` object and/or the color attribute to harmonize with:

```
```java
HarmonizedColorsOptions options =
new HarmonizedColorsOptions.Builder()
.setColorResourceIds(colorResources)
Expand All @@ -436,21 +436,21 @@ HarmonizedColorsOptions options =
In the `HarmonizedColorsOptions` class, we also provided a convenience method
`createMaterialDefaults()`, with Error colors being harmonized by default.

```
```java
HarmonizedColorsOptions options = HarmonizedColorsOptions.createMaterialDefaults();
HarmonizedColors.applyToContextIfAvailable(context, options);
```

If you need to harmonize color resources at runtime to a context and use the
harmonized color resources in xml, call:

```
```java
HarmonizedColors.applyToContextIfAvailable(context, harmonizedColorsOptions);
```

To return a new `Context` with color resources being harmonized, call:

```
```java
HarmonizedColors.wrapContextIfAvailable(context, harmonizedColorsOptions);
```

Expand Down Expand Up @@ -485,7 +485,7 @@ Here is an example of how we harmonize Error colors with theme overlay, to avoid
accidentally overriding the resources from the main theme/context. We have an
array of color attributes defined as:

```
```java
private static final int[] HARMONIZED_MATERIAL_ATTRIBUTES =
new int[] {
R.attr.colorError,
Expand All @@ -497,7 +497,7 @@ private static final int[] HARMONIZED_MATERIAL_ATTRIBUTES =

And a theme overlay defined as:

```
```xml
<style name="ThemeOverlay.Material3.HarmonizedColors" parent="">
<item name="colorError">@color/material_harmonized_color_error</item>
<item name="colorOnError">@color/material_harmonized_color_on_error</item>
Expand All @@ -522,7 +522,7 @@ If you would like to harmonize additional color attributes along with
harmonizing Error roles by default, the `HarmonizedColorAttributes` would look
like:

```
```java
HarmonizedColorAttributes.create(
ArrayUtils.addAll(createMaterialDefaults().getAttributes(), myAppAttributes),
R.style.ThemeOverlay_MyApp_HarmonizedColors);
Expand All @@ -539,7 +539,7 @@ dynamic colors have been applied, to ensure visual cohesion for reserved colors
suggested default when applying dynamic colors, is to harmonize M3 Error colors
in the callback when constructing `DynamicColorsOptions`:

```
```java
DynamicColorsOptions dynamicColorOptions =
new DynamicColorsOptions.Builder(activity)
...
Expand All @@ -558,7 +558,7 @@ generated from applying dynamic colors when constructing
`wrapContextIfAvailable(harmonizedColorsOptions)` to apply resources
harmonization:

```
```java
Context newContext = DynamicColors.wrapContextIfAvailable(getContext());

HarmonizedColorsOptions options =
Expand Down Expand Up @@ -594,12 +594,12 @@ Name | Method | Description
The library provides the following two helper methods in the `MaterialColors`
class which return the above-mentioned `ColorRoles` object:

```
```java
ColorRoles colorRoles = MaterialColors.getColorRoles(context, color);
```

or

```
```java
ColorRoles colorRoles = MaterialColors.getColorRoles(color, /* isLightTheme= */ booleanValue);
```