[ Web Proxy ]
URL:
Viewing: http://developer.android.com/develop/ui/compose/touch-input/stylus-input/ink-api-draw-stroke [Back]  [Original]

Draw a stroke  |  Jetpack Compose  |  Android Developers Skip to main content
Essentials Design & Plan Develop Google Play Blog
Search:
Android Studio
Android Developers [Android Developers]

Draw a stroke Stay organized with collections Save and categorize content based on your preferences.

To help you author strokes in an idiomatic Compose way, the Ink API provides Compose interoperability modules for authoring, brush, and geometry.

To draw a stroke in Compose, use the InProgressStrokes composable that requires a default brush instance, a way to override the default brush, and a callback that handles finished strokes.

  1. Set up UI component

    InProgressStrokes(
      defaultBrush = currentBrush,
      nextBrush = onGetNextBrush,
      onStrokesFinished = onStrokesFinished,
    )
    
  2. Handle finished strokes

    When wet strokes become dry, they are passed to the application through the onStrokesFinished callback argument of InProgressStrokes.

    Your app must pass the finished strokes to another Composable within the same UI thread to commit them to the screen.

    @Composable
    fun DrawingScreen(
      finishedStrokes: List<Strokes>,
      onStrokesFinished: (List<Stroke>) -> Unit,
      currentBrush: Brush,
      onGetNextBrush: () -> Brush,
      modifier: Modifier = Modifier
    ) {
      val canvasStrokeRenderer = remember { CanvasStrokeRenderer.create() }
    
      Box(modifier = Modifier.fillMaxSize()) {
          // The Canvas for drawing the permanent, dry strokes.
          Canvas(modifier = Modifier.fillMaxSize()) {
              finishedStrokes.forEach { stroke ->
                  canvasStrokeRenderer.draw(
                      stroke = stroke,
                      canvas = this,
                      strokeToScreenTransform = Matrix()
                  )
              }
          }
    
          //The wet ink layer for live drawing.
          // The InProgressStrokes composable for the wet ink layer goes here.
      }
    }
    
Define your brushes
Create interactive tools with the Geometry APIs

Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.

Last updated 2026-03-30 UTC.

[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2026-03-30 UTC."],[],[]]

Web Proxy Viewer  |  New URL  |  Original Page