# Custom Shape with Jetpack Compose

DevFeed: [Custom Shape with Jetpack Compose](<https://devfeed.tech/articles/custom-shape-with-jetpack-compose-25938.md>)

Original publisher: [Read original article](<https://juliensalvi.medium.com/custom-shape-with-jetpack-compose-1cb48a991d42?source=rss-cbfc736ddcd3------2>)

Author: Julien Salvi

Published: 2021-04-26T14:33:26Z

Content type: tutorial

Language: en

Sources: [Stories by Julien Salvi on Medium](<https://devfeed.tech/sources/stories-by-julien-salvi-on-medium.md>)

Topics: [Jetpack Compose](<https://devfeed.tech/topics/jetpack-compose.md>), [Compose](<https://devfeed.tech/topics/compose.md>), [Canvas](<https://devfeed.tech/topics/canvas.md>), [API](<https://devfeed.tech/topics/api.md>), [Code](<https://devfeed.tech/topics/code.md>)

Tags: [android](<https://devfeed.tech/tags/android.md>), [android-development](<https://devfeed.tech/tags/android-development.md>), [androiddev](<https://devfeed.tech/tags/androiddev.md>), [api](<https://devfeed.tech/tags/api.md>), [canvas](<https://devfeed.tech/tags/canvas.md>), [code](<https://devfeed.tech/tags/code.md>), [compose](<https://devfeed.tech/tags/compose.md>), [google-developer-expert](<https://devfeed.tech/tags/google-developer-expert.md>), [how-to](<https://devfeed.tech/tags/how-to.md>), [jetpack-compose](<https://devfeed.tech/tags/jetpack-compose.md>)

## AI overview

This tutorial explains how to create custom shapes for Jetpack Compose composables. It covers built-in shapes, Modifier functions for applying shapes, the Path API, and two approaches for custom outlines: GenericShape or a Shape implementation that overrides createOutline(). It also introduces animated shapes.

## Source excerpt

After exploring the Jetpack Compose Canvas in a previous article, this new post will explain how you can draw and use a custom Shape for your Composables to give them a specific outline. The Jetpack Compose foundation library already provides common shapes but we'll see how to take advantage of the Path API to build custom outlines. We will go even further by adding some animations to our brand new shapes. Introduction to Shape With Jetpack Compose, it is easy to add some rounded or cut corners to your Composable thanks to the foundation library which provides several shapes: RoundedCornerShape(): to have a rounded corner outline with a given radius CutCornerShape(): to have a cut corner outline with a given size GenericShape(): to build custom outlines with a given Path For example, a CutCornerShape with a corner size of 32dp applied to a Text Composable looks like the following image: CutCornerShape Shapes can be applied to your Composable thanks to by using several Modifier functions. Let's have a look at them: background(color, shape): it will define the new outline of the Composable with a given Color or Brush. graphicsLayer{}: set the shape attribute to define the new outline. Do not forget to set clip to true if you want that the shadow elevation matches the outline. border(width, color, shape): for drawing a border around the composable with a given shape, width and color. drawBehind{}: accessing the DrawScope and the Canvas to draw the outline of the composable. We can combine multiple Modifier methods to get the shape you can see above. The order matters when chaining the Modifier functions! For example, be sure to always call background() after graphicsLayer{} to ensure that your Composable will be correctly painted with the right color. Here is the code snippet of the Composable. https://medium.com/media/0d9ccf4b24727e20c1e32cd80016b24d/href Now that we've had a glimpse at the capabilities of shapes and how to use them, let's see how we can build our own