Skip to content

Commit 5eafe9b

Browse files
Arashvscodedsn5ft
authored andcommitted
[Docs] Update color.md to have better java/xml code snippet formatting
Resolves #3158 GIT_ORIGIN_REV_ID=c511ce410df4d54126893e1ed4275049143d050d PiperOrigin-RevId: 508390707
1 parent 8014267 commit 5eafe9b

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

docs/theming/Color.md

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ want to consider getting those tonal surface colors on the fly, by using the
159159
convenient enums we provide in the Material Library. For example, if you want to
160160
get the color hex value of Surface1, you can do:
161161

162-
```
162+
```java
163163
int colorSurface1 = SurfaceColors.SURFACE_1.getColor(context);
164164
```
165165

@@ -199,7 +199,7 @@ this helper class according to different scenarios:
199199

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

202-
```
202+
```java
203203
DynamicColors.applyToActivitiesIfAvailable(this);
204204
```
205205

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

217-
```
217+
```java
218218
DynamicColors.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) -> {
223223
Or provide your own customized dynamic color theme overlays, likely inheriting
224224
from the Material3 theme overlays above, by doing:
225225

226-
```
226+
``` java
227227
DynamicColors.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
240240
calling the following method in your activities’ `onCreate()` method (or before
241241
you inflate anything from it):
242242

243-
```
243+
```java
244244
DynamicColors.applyToActivityIfAvailable(this);
245245
```
246246

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

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

276-
```
276+
```java
277277
DynamicColorsOptions 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.
289289
The easiest solution is to create a themed context to create the view. We
290290
provide a helper method for this purpose:
291291

292-
```
292+
```java
293293
context = DynamicColors.wrapContextIfAvailable(context);
294294
```
295295

@@ -415,7 +415,7 @@ package:
415415

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

418-
```
418+
```java
419419
int harmonizedColor = MaterialColors.harmonizeWithPrimary(context, colorToHarmonize);
420420
```
421421

@@ -436,7 +436,7 @@ construct a `HarmonizedColorsOptions`. You can optionally pass in an array of
436436
resource 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
440440
HarmonizedColorsOptions options =
441441
new HarmonizedColorsOptions.Builder()
442442
.setColorResourceIds(colorResources)
@@ -448,21 +448,21 @@ HarmonizedColorsOptions options =
448448
In the `HarmonizedColorsOptions` class, we also provided a convenience method
449449
`createMaterialDefaults()`, with Error colors being harmonized by default.
450450

451-
```
451+
```java
452452
HarmonizedColorsOptions options = HarmonizedColorsOptions.createMaterialDefaults();
453453
HarmonizedColors.applyToContextIfAvailable(context, options);
454454
```
455455

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

459-
```
459+
```java
460460
HarmonizedColors.applyToContextIfAvailable(context, harmonizedColorsOptions);
461461
```
462462

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

465-
```
465+
```java
466466
HarmonizedColors.wrapContextIfAvailable(context, harmonizedColorsOptions);
467467
```
468468

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

500-
```
500+
```java
501501
private 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

510510
And 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
534534
harmonizing Error roles by default, the `HarmonizedColorAttributes` would look
535535
like:
536536

537-
```
537+
```java
538538
HarmonizedColorAttributes.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
551551
suggested default when applying dynamic colors, is to harmonize M3 Error colors
552552
in the callback when constructing `DynamicColorsOptions`:
553553

554-
```
554+
```java
555555
DynamicColorsOptions dynamicColorOptions =
556556
new DynamicColorsOptions.Builder(activity)
557557
...
@@ -570,7 +570,7 @@ generated from applying dynamic colors when constructing
570570
`wrapContextIfAvailable(harmonizedColorsOptions)` to apply resources
571571
harmonization:
572572

573-
```
573+
```java
574574
Context newContext = DynamicColors.wrapContextIfAvailable(getContext());
575575

576576
HarmonizedColorsOptions options =
@@ -606,12 +606,12 @@ Name | Method | Description
606606
The library provides the following two helper methods in the `MaterialColors`
607607
class which return the above-mentioned `ColorRoles` object:
608608

609-
```
609+
```java
610610
ColorRoles colorRoles = MaterialColors.getColorRoles(context, color);
611611
```
612612

613613
or
614614

615-
```
615+
```java
616616
ColorRoles colorRoles = MaterialColors.getColorRoles(color, /* isLightTheme= */ booleanValue);
617617
```

0 commit comments

Comments
 (0)