@@ -159,7 +159,7 @@ want to consider getting those tonal surface colors on the fly, by using the
159159convenient enums we provide in the Material Library. For example, if you want to
160160get the color hex value of Surface1, you can do:
161161
162- ```
162+ ``` java
163163int colorSurface1 = SurfaceColors . SURFACE_1. getColor(context);
164164```
165165
@@ -199,7 +199,7 @@ this helper class according to different scenarios:
199199
200200In your application class’ ` onCreate() ` method, call:
201201
202- ```
202+ ``` java
203203DynamicColors . applyToActivitiesIfAvailable(this );
204204```
205205
@@ -214,7 +214,7 @@ If you are using Material 3 themes, `R.attr.dynamicColorThemeOverlay` will be
214214You can also have finer control over theme overlay deployment by providing a
215215precondition when calling the method:
216216
217- ```
217+ ``` java
218218DynamicColors . applyToActivitiesIfAvailable(this , (activity, themeResId) - > {
219219 // ...implement your own logic here. Return `true` if dynamic colors should be applied.
220220});
@@ -223,7 +223,7 @@ DynamicColors.applyToActivitiesIfAvailable(this, (activity, themeResId) -> {
223223Or provide your own customized dynamic color theme overlays, likely inheriting
224224from the Material3 theme overlays above, by doing:
225225
226- ```
226+ ``` java
227227DynamicColors . applyToActivitiesIfAvailable(this , R . style. ThemeOverlay_MyApp_DynamicColors_DayNight );
228228```
229229
@@ -240,7 +240,7 @@ You can also opt to apply dynamic colors to a few specific activities, by
240240calling the following method in your activities’ ` onCreate() ` method (or before
241241you inflate anything from it):
242242
243- ```
243+ ``` java
244244DynamicColors . applyToActivityIfAvailable(this );
245245```
246246
@@ -258,7 +258,7 @@ precondition, to have finer control over theme overlay deployment. You may also
258258optionally specify an ` OnAppliedCallback ` function, which will be called after
259259dynamic colors have been applied:
260260
261- ```
261+ ``` java
262262DynamicColorsOptions dynamicColorOptions =
263263 new DynamicColorsOptions .Builder ()
264264 .setThemeOverlay(themeOverlay)
@@ -273,7 +273,7 @@ DynamicColors.applyToActivitiesIfAvailable(application, dynamicColorOptions);
273273You can also apply dynamic colors to a specific activity in the app by passing
274274in the specific activity and a ` DynamicColorsOptions ` object:
275275
276- ```
276+ ``` java
277277DynamicColorsOptions dynamicColorOptions =
278278 new DynamicColorsOptions .Builder ()
279279 .setThemeOverlay(themeOverlay)
@@ -289,7 +289,7 @@ Applying dynamic colors to a few of the views in an activity is more complex.
289289The easiest solution is to create a themed context to create the view. We
290290provide a helper method for this purpose:
291291
292- ```
292+ ``` java
293293context = DynamicColors . wrapContextIfAvailable(context);
294294```
295295
@@ -415,7 +415,7 @@ package:
415415
416416In your application class or activity/fragment/view, call:
417417
418- ```
418+ ``` java
419419int harmonizedColor = MaterialColors . harmonizeWithPrimary(context, colorToHarmonize);
420420```
421421
@@ -436,7 +436,7 @@ construct a `HarmonizedColorsOptions`. You can optionally pass in an array of
436436resource ids for the color resources you'd like to harmonize, a
437437` HarmonizedColorAttributes ` object and/or the color attribute to harmonize with:
438438
439- ```
439+ ``` java
440440HarmonizedColorsOptions options =
441441 new HarmonizedColorsOptions .Builder ()
442442 .setColorResourceIds(colorResources)
@@ -448,21 +448,21 @@ HarmonizedColorsOptions options =
448448In the ` HarmonizedColorsOptions ` class, we also provided a convenience method
449449` createMaterialDefaults() ` , with Error colors being harmonized by default.
450450
451- ```
451+ ``` java
452452HarmonizedColorsOptions options = HarmonizedColorsOptions . createMaterialDefaults();
453453HarmonizedColors . applyToContextIfAvailable(context, options);
454454```
455455
456456If you need to harmonize color resources at runtime to a context and use the
457457harmonized color resources in xml, call:
458458
459- ```
459+ ``` java
460460HarmonizedColors . applyToContextIfAvailable(context, harmonizedColorsOptions);
461461```
462462
463463To return a new ` Context ` with color resources being harmonized, call:
464464
465- ```
465+ ``` java
466466HarmonizedColors . wrapContextIfAvailable(context, harmonizedColorsOptions);
467467```
468468
@@ -497,7 +497,7 @@ Here is an example of how we harmonize Error colors with theme overlay, to avoid
497497accidentally overriding the resources from the main theme/context. We have an
498498array of color attributes defined as:
499499
500- ```
500+ ``` java
501501private static final int [] HARMONIZED_MATERIAL_ATTRIBUTES =
502502 new int [] {
503503 R . attr. colorError,
@@ -509,7 +509,7 @@ private static final int[] HARMONIZED_MATERIAL_ATTRIBUTES =
509509
510510And a theme overlay defined as:
511511
512- ```
512+ ``` xml
513513<style name =" ThemeOverlay.Material3.HarmonizedColors" parent =" " >
514514 <item name =" colorError" >@color/material_harmonized_color_error</item >
515515 <item name =" colorOnError" >@color/material_harmonized_color_on_error</item >
@@ -534,7 +534,7 @@ If you would like to harmonize additional color attributes along with
534534harmonizing Error roles by default, the ` HarmonizedColorAttributes ` would look
535535like:
536536
537- ```
537+ ``` java
538538HarmonizedColorAttributes . create(
539539 ArrayUtils . addAll(createMaterialDefaults(). getAttributes(), myAppAttributes),
540540 R . style. ThemeOverlay_MyApp_HarmonizedColors );
@@ -551,7 +551,7 @@ dynamic colors have been applied, to ensure visual cohesion for reserved colors
551551suggested default when applying dynamic colors, is to harmonize M3 Error colors
552552in the callback when constructing ` DynamicColorsOptions ` :
553553
554- ```
554+ ``` java
555555DynamicColorsOptions dynamicColorOptions =
556556 new DynamicColorsOptions .Builder (activity)
557557 ...
@@ -570,7 +570,7 @@ generated from applying dynamic colors when constructing
570570` wrapContextIfAvailable(harmonizedColorsOptions) ` to apply resources
571571harmonization:
572572
573- ```
573+ ``` java
574574Context newContext = DynamicColors . wrapContextIfAvailable(getContext());
575575
576576HarmonizedColorsOptions options =
@@ -606,12 +606,12 @@ Name | Method | Description
606606The library provides the following two helper methods in the ` MaterialColors `
607607class which return the above-mentioned ` ColorRoles ` object:
608608
609- ```
609+ ``` java
610610ColorRoles colorRoles = MaterialColors . getColorRoles(context, color);
611611```
612612
613613or
614614
615- ```
615+ ``` java
616616ColorRoles colorRoles = MaterialColors . getColorRoles(color, /* isLightTheme= */ booleanValue);
617617```
0 commit comments