# MaterialTheme

Version: 0.5.0
Framework commit: d503df2befa756e681fcdc6250e9552dc7388bea
Canonical URL: /docs/0.5.0/api/ferroui-themes-material/struct-materialtheme/

**struct** · [`ferroui-themes-material`](/docs/0.5.0/api/ferroui-themes-material/) · v0.5.0

```rust
struct MaterialTheme
```

Includes the Android Material theme in an application.

[View source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Themes.Material/material_theme.rs#L45)

## Members

- [`use_android_dynamic_colors`](#function-use_android_dynamic_colors)
- [`refresh_android_dynamic_colors`](#function-refresh_android_dynamic_colors)
- [`stop_android_dynamic_colors`](#function-stop_android_dynamic_colors)
- [`TYPE`](#assoc_const-type)
- [`to_ref`](#function-to_ref)
- [`motion_scheme_property`](#function-motion_scheme_property)
- [`reduced_motion_property`](#function-reduced_motion_property)
- [`density_style_property`](#function-density_style_property)
- [`DOCUMENT_URI`](#assoc_const-document_uri)
- [`high_contrast`](#function-high_contrast)
- [`construct`](#function-construct)
- [`new`](#function-new)
- [`with_service_provider`](#function-with_service_provider)
- [`with_parts`](#function-with_parts)
- [`density_style`](#function-density_style)
- [`set_density_style`](#function-set_density_style)
- [`set_color_scheme`](#function-set_color_scheme)
- [`motion_scheme`](#function-motion_scheme)
- [`set_motion_scheme`](#function-set_motion_scheme)
- [`reduced_motion`](#function-reduced_motion)
- [`set_reduced_motion`](#function-set_reduced_motion)
- [`try_get_resource`](#function-try_get_resource)
- [`as_style`](#function-as_style)
- [`as_resource_provider`](#function-as_resource_provider)

<a id="function-use_android_dynamic_colors"></a>

### use_android_dynamic_colors

```rust
fn use_android_dynamic_colors(self: &Self) -> Result<MaterialAndroidColorSource, MaterialAndroidColorError>
```

Imports the device's light and dark wallpaper color schemes and refreshes them when
FerroUI's platform settings report changed colors or theme configuration.

Enable the `android-dynamic-color` Cargo feature and call this after the Android
application is initialized. The bridge obtains the existing application context itself;
it requires no Java code, AndroidX library, resource packaging, or JNI setup in the app.
Repeating this call replaces the previous subscription. The subscription is disposed
when the theme is dropped or `Self::stop_android_dynamic_colors` is called.

On API 34+ all system roles, including fixed colors and current system contrast, are
imported directly. API 31–33 uses AndroidX's five tonal palettes and float CAM16/HCT
neutral-tone derivation. Older systems return an error and retain the existing palette.
Desktop builds do not link the Android backend and return `UnsupportedPlatform`.

Call `Self::refresh_android_dynamic_colors` on a custom host notification if that host
changes Android resource overlays without a FerroUI platform color-change notification.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Themes.Material/android_colors.rs#L88)

<a id="function-refresh_android_dynamic_colors"></a>

### refresh_android_dynamic_colors

```rust
fn refresh_android_dynamic_colors(self: &Self) -> Result<MaterialAndroidColorSource, MaterialAndroidColorError>
```

Re-reads the current native palette. Both variants are validated before either is
installed. This is also useful after custom Android resource-overlay changes.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Themes.Material/android_colors.rs#L99)

<a id="function-stop_android_dynamic_colors"></a>

### stop_android_dynamic_colors

```rust
fn stop_android_dynamic_colors(self: &Self)
```

Stops following platform changes while retaining the most recently imported colors.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Themes.Material/android_colors.rs#L122)

<a id="assoc_const-type"></a>

### TYPE

```rust
const TYPE: &'static $crate::TypeInfo
```

The runtime type of this class.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Themes.Material/material_theme.rs#L59)

<a id="function-to_ref"></a>

### to_ref

```rust
fn to_ref(self: &Self) -> $crate::Ref<MaterialTheme>
```

Returns a strong reference to this object.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Themes.Material/material_theme.rs#L59)

<a id="function-motion_scheme_property"></a>

### motion_scheme_property

```rust
fn motion_scheme_property() -> &'static DirectProperty<MaterialTheme, MaterialMotionScheme>
```

The Material spring scheme used by control transitions.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Themes.Material/material_theme.rs#L94)

<a id="function-reduced_motion_property"></a>

### reduced_motion_property

```rust
fn reduced_motion_property() -> &'static DirectProperty<MaterialTheme, bool>
```

Disables nonessential motion. Platform accessibility settings are also honored.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Themes.Material/material_theme.rs#L94)

<a id="function-density_style_property"></a>

### density_style_property

```rust
fn density_style_property() -> &'static DirectProperty<MaterialTheme, DensityStyle>
```

Defines the `DensityStyle` property.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Themes.Material/material_theme.rs#L94)

<a id="assoc_const-document_uri"></a>

### DOCUMENT_URI

```rust
const DOCUMENT_URI: &'static str
```

The URI of the document of the class.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Themes.Material/material_theme.rs#L122)

<a id="function-high_contrast"></a>

### high_contrast

```rust
fn high_contrast() -> ThemeVariant
```

Material's generated high-contrast dark scheme. Request it with
`window.set_requested_theme_variant(Some(MaterialTheme::high_contrast()))`
or `RequestedThemeVariant="{x:Static material:MaterialTheme.HighContrast}"`.
Applications can replace its palette with `Self::set_color_scheme`.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Themes.Material/material_theme.rs#L128)

<a id="function-construct"></a>

### construct

```rust
fn construct() -> Self
```

Field initialisation; see `Styles::construct`.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Themes.Material/material_theme.rs#L133)

<a id="function-new"></a>

### new

```rust
fn new() -> Ref<Self>
```

Creates the theme.
## Panics
Panics if the documents of the theme fail to load.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Themes.Material/material_theme.rs#L151)

<a id="function-with_service_provider"></a>

### with_service_provider

```rust
fn with_service_provider(sp: Option<Rc<dyn IServiceProvider>>) -> Ref<Self>
```

Creates the theme; `sp` is the parent's service provider.

The full theme: every unit of its compiled markup. A later load of the theme by URI gets the
full theme too, unless the application registered the units it keeps.
## Panics
Panics if the documents of the theme fail to load, or if the loaded
document lacks the compact styles.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Themes.Material/material_theme.rs#L163)

<a id="function-with_parts"></a>

### with_parts

```rust
fn with_parts(sp: Option<Rc<dyn IServiceProvider>>, parts: rt::ThemeParts) -> Ref<Self>
```

Creates the theme from some of the units of its compiled markup (#568, docs/porting/theme-trimming.md);
`sp` is the parent's service provider.

`parts` are units of `crate::compiled_xaml::THEME_UNITS`, in canonical order (ascending
indices), with the ambient unit (index 0) first: the table an application's build writes
when it trims its themes (the default; `[package.metadata.ferroui] theme-trimming = false`
turns it off). The theme applies those units, at the places of the full theme and in its
order; a unit that `parts` leaves out adds nothing. Only the units named are linked into the
application. The color schemes and the motion resources are set as for the full theme. In
debug builds a lookup of a control theme that `parts` left out logs once that it was trimmed.
## Panics
Panics if the documents of the theme fail to load, or if `parts` leaves out the ambient
unit (index 0), which has the structure of the theme and the compact styles.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Themes.Material/material_theme.rs#L183)

<a id="function-density_style"></a>

### density_style

```rust
fn density_style(self: &Self) -> DensityStyle
```

The density style of the theme (normal, compact).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Themes.Material/material_theme.rs#L250)

<a id="function-set_density_style"></a>

### set_density_style

```rust
fn set_density_style(self: &Self, value: DensityStyle)
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Themes.Material/material_theme.rs#L254)

<a id="function-set_color_scheme"></a>

### set_color_scheme

```rust
fn set_color_scheme(self: &Self, variant: ThemeVariant, scheme: &MaterialColorScheme)
```

Replaces every color role and its state brushes atomically for a variant.
Supply a full Android dynamic-color or Material Theme Builder scheme here.
Existing controls update through DynamicResource without rebuilding their templates.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Themes.Material/material_theme.rs#L261)

<a id="function-motion_scheme"></a>

### motion_scheme

```rust
fn motion_scheme(self: &Self) -> MaterialMotionScheme
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Themes.Material/material_theme.rs#L266)

<a id="function-set_motion_scheme"></a>

### set_motion_scheme

```rust
fn set_motion_scheme(self: &Self, value: MaterialMotionScheme)
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Themes.Material/material_theme.rs#L270)

<a id="function-reduced_motion"></a>

### reduced_motion

```rust
fn reduced_motion(self: &Self) -> bool
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Themes.Material/material_theme.rs#L274)

<a id="function-set_reduced_motion"></a>

### set_reduced_motion

```rust
fn set_reduced_motion(self: &Self, value: bool)
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Themes.Material/material_theme.rs#L278)

<a id="function-try_get_resource"></a>

### try_get_resource

```rust
fn try_get_resource(self: &Self, key: &ResourceKey, theme: Option<&ThemeVariant>) -> Option<ResourceValue>
```

Tries to find a resource within the theme: the compact resources are
checked first when the density style is compact.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Themes.Material/material_theme.rs#L318)

<a id="function-as_style"></a>

### as_style

```rust
fn as_style(self: &Self) -> Rc<dyn IStyle>
```

The theme as a style, for the style collections of applications and
elements (`application.styles().add(theme.as_style())`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Themes.Material/material_theme.rs#L344)

<a id="function-as_resource_provider"></a>

### as_resource_provider

```rust
fn as_resource_provider(self: &Self) -> Rc<dyn IResourceProvider>
```

The theme as a resource provider.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Themes.Material/material_theme.rs#L349)

## Trait implementations

- `Send`
- `Sync`
- `Freeze`
- `UnsafeUnpin`
- `Unpin`
- `UnwindSafe`
- `RefUnwindSafe`
- `Borrow<T>`
- `BorrowMut<T>`
- `Into<U>`
- `From<T>`
- `TryInto<U>`
- `TryFrom<U>`
- [`Receiver`](/docs/0.5.0/api/ferroui-system/task/oneshot/struct-receiver/)
- `Any`
- [`FerroObjectImplExt`](/docs/0.5.0/api/ferroui-base/trait-ferroobjectimplext/)
- [`ClassDefaults`](/docs/0.5.0/api/ferroui-base/trait-classdefaults/)
- `ErasedDestructor`
- `IntoEither`
- `CastableFrom<ST, Uninit, Uninit>`
- `CastableFrom<ST, Initialized, Initialized>`
- `Read<Exclusive, BecauseExclusive>`
- `Deref`
- [`Upcast<T>`](/docs/0.5.0/api/ferroui-base/trait-upcast/)
- [`Upcast<MaterialTheme>`](/docs/0.5.0/api/ferroui-base/trait-upcast/)
- [`StaticType`](/docs/0.5.0/api/ferroui-base/trait-statictype/)
- [`ObjectType`](/docs/0.5.0/api/ferroui-base/trait-objecttype/)
- [`Subclassable<T>`](/docs/0.5.0/api/ferroui-base/trait-subclassable/)
- [`DefaultConstructible`](/docs/0.5.0/api/ferroui-base/trait-defaultconstructible/)
- [`FerroObjectImpl`](/docs/0.5.0/api/ferroui-base/trait-ferroobjectimpl/)

## Availability

Extracted for `aarch64-apple-darwin`. Cargo features are listed in the [crate index](/docs/0.5.0/api/).
