Android Signature Pad
Android Signature Pad is an Android library for drawing smooth signatures. It uses variable width Bézier curve interpolation based on Smoother Signatures post by Square.
- Bézier implementation for a smoother line
- Variable point size based on velocity
- Customizable pen color and size
- Optional live finger shadow on Android 13+
- Bitmap, SVG and raw signature data export
- Jetpack Compose state API and classic Android Views
- Undo/redo completed strokes and restore saved signatures
The latest published version is listed on Maven Central. The library supports Android 6.0 (API 23) and newer.
Declare Maven Central in your settings.gradle.kts:
dependencyResolutionManagement {
repositories {
google()
mavenCentral()
}
}Then, include the library as dependency:
implementation("se.warting.signature:signature-pad:<latest_version>") // Jetpack Composeor
implementation("se.warting.signature:signature-view:<latest_version>") // Android ViewsPlease see the /app example app for a more detailed code example of how to use the
library.
Hoist the signature state and give the drawing area an explicit size:
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.material3.Button
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import se.warting.signaturepad.SignaturePadView
import se.warting.signaturepad.rememberSignaturePadState
@Composable
fun SignatureForm(onSave: (String) -> Unit) {
val signatureState = rememberSignaturePadState()
Column {
SignaturePadView(
state = signatureState,
modifier = Modifier.fillMaxWidth().height(200.dp),
)
Row {
Button(onClick = { signatureState.undo() }) { Text("Undo") }
Button(onClick = { signatureState.clear() }) { Text("Clear") }
Button(onClick = { onSave(signatureState.getSignatureSvg()) }) { Text("Save") }
}
}
}rememberSignaturePadState() preserves signature events across configuration changes using
rememberSaveable. Use isEmpty and canUndo() to inspect the current state, and the
onStartSigning, onSigning, onSigned, and onClear callbacks to respond to input.
Existing named-argument onReady integrations still work after recompilation, but the adapter is deprecated.
For new code, use SignaturePadState as shown above.
Version 0.3.0 introduces the native Compose state API. Recompile consumers of signature-pad:
the Compose function's JVM signature has changed since 0.2.0. Calls using positional arguments
must account for the new state parameter after modifier; named arguments are recommended.
Direct construction of SignaturePadAdapter(view) is no longer supported: use
rememberSignaturePadState(), or obtain the deprecated adapter through onReady.
The classic View API remains available in signature-view.
SignatureField adds a decorative guideline and a placeholder slot around the
native Compose canvas. Provide localized text and your app's colors:
val state = rememberSignaturePadState()
SignatureField(
state = state,
modifier = Modifier.fillMaxWidth().height(200.dp),
guidelineColor = MaterialTheme.colorScheme.outline,
penColor = MaterialTheme.colorScheme.onSurface,
) {
Text("Sign here")
}Import se.warting.signaturepad.SignatureField. The placeholder is visible only
while the signature is empty. The guideline and placeholder never appear in bitmap,
SVG or raw-event exports. Set showGuideline = false to hide the line. Use
SignaturePadView directly for signing callbacks and advanced configuration.
The Compose sample includes working AlertDialog and ModalBottomSheet capture
flows in SignatureCaptureExamples.kt: Save is enabled after input, Clear resets
the field, and Cancel leaves the previously saved preview untouched. Material 3 is
used by the sample; the library component itself only requires Compose Foundation.
<se.warting.signatureview.views.SignaturePad
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/signature_pad"
android:layout_width="match_parent"
android:layout_height="200dp" />Use clear(), undo(), redo(), canUndo(), canRedo(), and the export methods on the view. Register a
SignedListener with setOnSignedListener() for signing callbacks. See the sample app for
XML attributes and data binding examples.
undo() removes the most recent completed stroke; redo() restores it. Both preserve an
in-progress stroke. canUndo() and canRedo() are observable in Compose. New accepted
input, clear() and explicit signature restoration discard redo history. Redo history
is transient and is not included in saved signatures or configuration-state restoration.
History stores input coordinates and timing, not per-stroke pen styles. As with undo and signature restoration in 0.3.0, replay uses the current pen color, width and velocity settings for the entire signature. Changing those settings between capture and undo/redo can therefore restyle existing ink. Keep pen settings fixed during a capture when its appearance must remain unchanged.
penMinWidth- The minimum width of the stroke (default: 3dp).penMaxWidth- The maximum width of the stroke (default: 7dp).penColor- The color of the stroke (default: Color.BLACK).velocityFilterWeight- Weight used to modify new velocity based on the previous velocity ( default: 0.9).clearOnDoubleClick- Double click to clear pad (default: false)
Call these methods on SignaturePadState or the classic SignaturePad view:
-
getSignatureBitmap()- A signature bitmap with a default white background. You can also customize the image's coloring e.g.getSignatureBitmap(backgroundColor: Int, penColor: Int) -
getTransparentSignatureBitmap(trimBlankSpace: Boolean = false)- A signature bitmap with a transparent background. SettrimBlankSpace = trueto crop the bitmap to the signature bounds, removing surrounding blank space. You can also customize the image's coloring, e.g.getTransparentSignatureBitmap(penColor: Int) -
getSignatureSvg()- A signature Scalable Vector Graphics document. The default SVG stroke is black; usegetSignatureSvg(penColor, backgroundColor)to override its colors.
Raw event persistence and standalone rendering are available with @OptIn(ExperimentalSignatureApi::class):
getSignature() / setSignature(signature) save and restore events, while Signature.toBitmap(),
Signature.toTransparentBitmap(), and Signature.toSvg() render without a view. Import the rendering
extensions from se.warting.signaturecore. These APIs are experimental.
Both Compose SignaturePadState and the classic SignaturePad view expose:
val options = SignatureExportOptions(
trimBlankSpace = true,
paddingPixels = 16,
backgroundColor = android.graphics.Color.WHITE,
penColor = android.graphics.Color.BLACK,
)
val png: ByteArray? = signatureState.toPngByteArray(options)
val base64: String? = signatureState.toBase64(options)
val bitmap: Bitmap? = signatureState.exportBitmap(options)Import se.warting.signaturecore.SignatureExportOptions. The same methods are
extensions on SignatureSDK, imported from se.warting.signaturecore.
The methods return null before a raster surface has been initialized. Empty
signatures retain the canvas size, plus padding. Cropping happens before background
fill; padding adds pixels on every edge and does not remove ink at canvas edges.
Defaults preserve the full canvas with a transparent background and no padding.
Base64 uses standard encoding without line breaks or a data:image/png;base64,
prefix. Exported bitmaps are independent copies owned by the caller.
On Android 13 (API 33) and newer, an optional shadow follows the active pointer. It is disabled by default and never becomes part of bitmap, SVG, or raw event exports. Older Android versions and software-rendered canvases keep working without drawing the shadow.
SignaturePadView(
state = signatureState,
shadowIntensity = 0.5f, // 0..1; explicitly selects the shadow-enabled overload
shadowColor = Color.Black,
shadowAngleDegrees = 50.710594f,
)For Views, use setShadowIntensity, setShadowColor, and setShadowAngleDegrees,
or the XML attributes shadowIntensity, shadowColor, and shadowAngleDegrees.
The Compose and View samples include a switch to try the effect.
The shader is adapted from Romain Guy's shadow-pointer sample.
Use JDK 21 and Android SDK 37. Set ANDROID_HOME or sdk.dir in your untracked
local.properties file. Both ordinary Git clones and linked worktrees are supported.
The published libraries support API 23 and newer; the sample app requires API 24 because of Navigation 3.
./gradlew check apiCheck :app:assembleDebugcheck runs unit tests, Android lint, and Detekt. Bitmap regression tests use Robolectric's
native graphics renderer; an emulator is not required. apiCheck verifies the committed API snapshots. check also runs apiCheckPublished, which
downloads the three 0.3.0 AARs from Maven Central, extracts their public JVM API, and rejects
removed or changed declarations even if the local snapshots were updated. Additive APIs are allowed.
Screenshot baselines use AGP's experimental Compose screenshot test suites. Install Git LFS
and run git lfs pull before validating them (CI checks out LFS assets automatically):
./gradlew :app:testDebugScreenshotTestDefaultTestSuite
# After an intentional visual change, regenerate and inspect the PNGs before committing:
./gradlew :app:updateDebugScreenshotTestDefaultTestSuiteBaselines live in app/src/screenshotTestDefaultDebug/reference/ and are stored in Git LFS.
Reports are under app/build/reports/tests/. Include rendered baseline images in visual PRs
using GitHub's LFS media URLs; do not embed the Git LFS pointer files.
Core owns live signing input (SignatureSDK.input) and signature restoration. View and Compose
adapt platform touch events, double-tap recognition, sizing and lifecycle notifications; core handles
the active pointer, cancel/clear/restore invalidation and replay on bitmap initialization. Explicit
restoration preserves signing callbacks; allocating a bitmap does not replay those callbacks.
Review dependency updates with the existing Version Catalog Update plugin:
./gradlew versionCatalogUpdate --interactive
# Review gradle/libs.versions.updates.toml before applying updates.
./gradlew versionCatalogApplyUpdates
./gradlew versionCatalogUpdate --check check apiCheck :app:assembleDebugThe catalog check prefers stable releases for dependencies already on stable versions. Gradle wrapper, settings plugins, and GitHub Actions versions must be checked separately.
The build uses AGP 9's built-in Kotlin support and new DSL. Compose and Parcelize use the same
Kotlin version as the compiler. The View library and sample app use AGP's legacy-kapt plugin
for data binding. API checks include both Kotlin and generated Java classes and run as part of check.
Release versions come from v* Git tags. Development versions use git describe, including the
commit and dirty suffix when applicable. To override the publication version, pass
-PVERSION_NAME=0.3.0-SNAPSHOT or set VERSION_NAME in local.properties.
Publishing a GitHub release with a vMAJOR.MINOR.PATCH tag triggers the release workflow.
It runs check, signs all three library artifacts, publishes them through the Central Portal,
and waits for publication to complete. The OSSRH_USERNAME / OSSRH_PASSWORD repository
secret names are retained, but their values must be Central Portal user-token credentials.
For Android stylus pressure and low-latency drawing, opt into the separate signature-ink
module. See Ink usage, exports and device tests. Existing rendering remains
available through signature-pad and signature-view; their APIs are unchanged.
The new signature-engine and signature-compose modules support Android, iOS, desktop and
WebAssembly. See multiplatform usage, examples and verification.
Existing Android consumers can keep using signature-core, signature-pad and signature-view.
