How do I create Custom Shapes in Compose application?
In this compose example we will learn about Shapes. Compose provided inbuilt shapes like Rectangle Shape, Circle Shape, Round Rectangle Shape. To get these shapes we need to apply clip property to Modifier compose function. All these Shapes are implements Shape Interface
@Immutable |
What we will cover
- Create Shape with Rectangle Shape
- Create Circle Shape
- Create Round Rectangle Shape
- Create Custom Shape
Let's get started
Step 1: To create new Jetpack project in Android studio please refer how to create new Project in Android studio using Jetpack compose
Step 2: Create Rectangle Shape
To create Rectangle Shape with compose we will use below code
Box( |
Create Circle Shape
|
Create Round Rectangle Shape
Box( |
How to Create Custom shapes
To create custom shapes with comose we need to create a class which extends Shape interface.
This interface contains unimplemented method createOutline() which we need to override in our custom class
class Customshape : Shape { |
Step 3: Run application on device/emulator, you will see below output on the screen
![]() |
Complete code for Create shapes in Compose application and create Custom shapes using shape interface.
package com.rrtutors.compose_tutorials import androidx.compose.ui.geometry.Size class Customshape : Shape { |
Conclusion: In this compose example we covered how to create shapes and create custom shapes with custom shape class.