Skip to content

Instantly share code, notes, and snippets.

View ricknout's full-sized avatar

Nick Rout ricknout

View GitHub Profile
@ricknout
ricknout / mdc_theme_overlay.xml
Created July 30, 2020 15:50
MDC-Android theme overlay
<!-- Copyright 2020 Google LLC.
SPDX-License-Identifier: Apache-2.0 -->
<!-- In res/values/themes.xml -->
<style name="ThemeOverlay.App.PrimarySecondary" parent="">
<item name="colorPrimary">?attr/colorSecondary</item>
<item name="colorOnPrimary">?attr/colorOnSecondary</item>
</style>
@ricknout
ricknout / mdc_theme_overlay_button.xml.diff
Created July 30, 2020 15:56
MDC-Android theme overlay in button
<!-- Copyright 2020 Google LLC.
SPDX-License-Identifier: Apache-2.0 -->
<Button
...
<!-- Alternatively apply with android:theme -->
+ app:materialThemeOverlay="@style/ThemeOverlay.App.PrimarySecondary"
/>
@ricknout
ricknout / mdc_color_custom_views.xml
Created July 31, 2020 09:14
MDC-Android color in custom views
<!-- Copyright 2020 Google LLC.
SPDX-License-Identifier: Apache-2.0 -->
<!-- In res/values/attrs.xml -->
<declare-styleable name="AppCustomView">
<attr name="backgroundTint" />
<attr name="titleTextColor" />
...
</declare-styleable>
@ricknout
ricknout / mdc_color_utilities.kt
Created July 31, 2020 09:17
MDC-Android color utilities
/* Copyright 2020 Google LLC.
SPDX-License-Identifier: Apache-2.0 */
// Resolve color from theme attr
val primaryColor = MaterialColors.getColor(
view, R.attr.colorPrimary
)
// Layer background color with overlay color + alpha
val overlayedColor = MaterialColors.layer(
@ricknout
ricknout / mdc_type_resources.xml
Created July 31, 2020 11:53
MDC-Android type resources
<!-- Copyright 2020 Google LLC.
SPDX-License-Identifier: Apache-2.0 -->
<!-- In res/values/type.xml -->
<style name="TextAppearance.App.Headline6" parent="TextAppearance.MaterialComponents.Headline6">
<item name="fontFamily">@font/roboto_mono</item>
...
</style>
<style name="TextAppearance.App.Body2" parent="TextAppearance.MaterialComponents.Body2">
<item name="fontFamily">@font/roboto_mono</item>
@ricknout
ricknout / mdc_letter_spacing.xml.diff
Created July 31, 2020 12:06
MDC-Android letter spacing
<!-- Copyright 2020 Google LLC.
SPDX-License-Identifier: Apache-2.0 -->
<!-- (0.25 tracking / 14sp font size) = 0.0178571429 em -->
<style name="TextAppearance.App.Body2" parent="TextAppearance.MaterialComponents.Body2">
<item name="fontFamily">@font/roboto_mono</item>
<item name="android:textSize">14sp</item>
+ <item name="android:letterSpacing">0.0178571429</item>
...
</style>
@ricknout
ricknout / mdc_custom_type_attr.xml
Created July 31, 2020 12:41
MDC-Android custom type attribute
<!-- Copyright 2020 Google LLC.
SPDX-License-Identifier: Apache-2.0 -->
<!-- In res/values/attrs.xml -->
<attr name="textAppearanceCustom" format="reference" />
<!-- In res/values/type.xml -->
<style name="TextAppearance.App.Custom" parent="TextAppearance.MaterialComponents.*">
...
</style>
@ricknout
ricknout / mdc_type_theme_attrs.xml
Created July 31, 2020 13:11
MDC-Android type theme attributes
<!-- Copyright 2020 Google LLC.
SPDX-License-Identifier: Apache-2.0 -->
<!-- In res/values/themes.xml -->
<style name="Theme.App.Base" parent="Theme.MaterialComponents.*">
...
<item name="textAppearanceHeadline6">
@style/TextAppearance.App.Headline6
</item>
<item name="textAppearanceBody2">
@ricknout
ricknout / mdc_type_custom_views.xml
Created July 31, 2020 13:29
MDC-Android type in custom views
<!-- Copyright 2020 Google LLC.
SPDX-License-Identifier: Apache-2.0 -->
<!-- In res/values/attrs.xml -->
<declare-styleable name="AppCustomView">
<attr name="titleTextAppearance" />
<attr name="subtitleTextAppearance" />
...
</declare-styleable>
@ricknout
ricknout / mdc_shape_resources.xml
Created July 31, 2020 13:55
MDC-Android shape resources
<!-- Copyright 2020 Google LLC.
SPDX-License-Identifier: Apache-2.0 -->
<!-- In res/values/shape.xml -->
<style name="ShapeAppearance.App.SmallComponent" parent="ShapeAppearance.MaterialComponents.SmallComponent">
<item name="cornerFamily">cut</item>
<item name="cornerSize">4dp</item>
...
</style>
<style name="ShapeAppearance.App.MediumComponent" parent="ShapeAppearance.MaterialComponents.MediumComponent">