Shape Theming


Material Design encourages brand expression through shapes. The Material Components library offers a shape library that can be used to create non-standard shapes.
The libraryshape provides a MaterialShapeDrawable class that can draw custom shapes while taking shadows, elevation, scale, and color into account.

Design & API Documentation

Usage

MaterialShapeDrawable draws itself using a path generated by provided CornerTreatments and EdgeTreatments. The shape library provides some subclassed CornerTreatments and EdgeTreatments to allow for easily building new shapes:
  • CutCornerTreatment
  • RoundedCornerTreatment
  • TriangleEdgeTreatment
Both CornerTreatment and EdgeTreatment can be subclassed to create custom corners and edges.
Note: The shape library is experimental and subject to change.

Coming Soon

We will be adding theming support for shapes to make the shapes of components themeable at the application level. This will allow an app to change shapes of components inside their apps just by specifying shape theme attributes.
Here’s an example of what this might look like: Let’s say you want to change the corners in your app to cut corners. You’d be able to specify attributes like cornerStylePrimary and cornerRadiusPrimary at the theme level. This might look something like this:
Then, Material components would read in those theme attributes and style themselves accordingly.
If you want to change a component’s corner style mapping, you’d be able to change the component’s style across the app. Let’s say you wanted to modify MaterialCardView so that it uses cornerRadiusSecondary instead of cornerRadiusPrimary. All you’d have to do is define your own card style that extends from the widget’s style, and set the component’s relevant attributes to the desired theme attributes:
And set the mapping to the custom component style in the theme:
This would apply the card corner attributes specified in Widget.MyApp.MyCard to all cards in the app. You can also set this style on individual components in your layout file:
Or you can set the attributes on the widget in your layout file to override the default behavior on a case-by-case basis:

Comments

Popular posts from this blog

Best and Free Hosting Servers!

What is an API?