[Shape] Equivalent of MaterialShape from compose
I want to use Material 3 shapes, but I couldnt really find any documentation on how create the actual shape sets
The only documentation I found was this
I was able to find it for compose https://developer.android.com/reference/kotlin/androidx/compose/material3/MaterialShapes
I am wondering how to create the same shape sets either through xml or programatically
Hey @brahmkshatriya
We do have a MaterialShapes class that can be used to set your View's background with View.setBackground(MaterialShapes.createShapeDrawable(MaterialShapes.<SHAPE>).
The class is currently set to @RestrictTo(Scope.LIBRARY_GROUP) which is why it's not in the documentation. Let me check with the team why it's restricted.
Thats awesome, I'd definitely like to use those shapes outside of the library
I spoke to the team about this. One of the main concerns is that MaterialShapes are designed to be used with square components - icon buttons, avatars, and other square/circular containers - and we're not sure how to expose them with that restriction in mind. If you applied a fans or gem shape to an Extended FAB, how would those shapes scale to fit a rectangle?
To help us think about if/how to expose this, could you tell us about how you plan to use the shapes?
- Where in your UI would you use them? As the background of Material Components or in some other part of your UI?
- Are you planning on using the AndroidX graphics-shapes lib to morph or work with the shapes?
If you want to try using them, you can add @SuppressWarnings("RestrictTo") to your calling method or class to get around the restricted API error. Just keep in mind that the API could change.
Things I would like to do with this:
- Use the MaterialShape for masking (ex. Image masked to material shape)
- As a background for button, something like this
- To use to it for creating a M3E SwipeRefreshLayout
IMO, its fine for the shapes to have an aspect ratio of 1:1, so you avoid having to think bout shapes that would not look good in different aspect ratios
Okay sounds good! Thanks for the info.
We're working on exposing the MaterialShapes class and it should be out soon.
class Material shspe not work
class Material shspe not work
loved the part where you sent the entire stack trace
Hey, any updates on this? @pekingme
Yes, this is still on our roadmap. Need some internal discussion about the APIs.