Stylus handwriting is enabled for all TextField components by default on
Android 14 and higher and the
androidx.compose.foundation:foundation:1.7.0
dependency. Handwriting mode is started for a TextField when a stylus motion
event is detected within the handwriting bounds of the component.
The handwriting bounds include 40 dp of vertical padding and 10 dp of horizontal
padding around the input field.
Figure 2. Handwriting bounds of TextField components.
Stylus handwriting is not supported for TextField fields when the input method
editor is requested with KeyboardType.Password.
Input delegation
Apps can display placeholder UI elements that appear to be text input fields but
are actually just static UI elements with no text input capability. Search
fields are a common example. Tapping the static UI element triggers a transition
to a new UI that contains a functional text input field focused for input.
Figure 3. Input delegation from static UI element to text input field.
Stylus input delegation
Use the handwriting delegation APIs to support stylus handwriting input for
placeholder input fields (see handwritingDetector and
handwritingHandler). The placeholder UI element is
configured to delegate handwriting to a functional input field. For an example
implementation, see
HandwritingDetectorSample.kt.
Stylus handwriting mode starts when the functional input field gains focus and
creates an
InputConnection.
Figure 4. Stylus input delegation from static UI element to text input field.
Testing
Stylus handwriting is supported on Android 14 and higher devices with a
compatible stylus input device and an input method
editor (IME) that
supports the Android 14 stylus handwriting APIs.
If you don't have a stylus input device, simulate stylus input on any device
with root access (including emulators) using the following Android Debug Bridge
(adb) commands:
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 2025-05-20 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 2025-05-20 UTC."],[],[],null,["# Stylus input in text fields\n\nThe Jetpack\n[`androidx.compose.material3`](/jetpack/androidx/releases/compose-material3)\nlibrary enables users to write into any [`TextField`](/reference/kotlin/androidx/compose/material/package-summary#TextField(androidx.compose.ui.text.input.TextFieldValue,kotlin.Function1,androidx.compose.ui.Modifier,kotlin.Boolean,kotlin.Boolean,androidx.compose.ui.text.TextStyle,kotlin.Function0,kotlin.Function0,kotlin.Function0,kotlin.Function0,kotlin.Boolean,androidx.compose.ui.text.input.VisualTransformation,androidx.compose.foundation.text.KeyboardOptions,androidx.compose.foundation.text.KeyboardActions,kotlin.Boolean,kotlin.Int,kotlin.Int,androidx.compose.foundation.interaction.MutableInteractionSource,androidx.compose.ui.graphics.Shape,androidx.compose.material.TextFieldColors)) component in\nany app using a stylus.\nYour browser doesn't support the video tag. **Figure 1.** Handwritten input with a stylus.\n\nTo enable stylus input by default, add the library dependency to your app's\n`build.gradle` file: \n\n### Kotlin\n\n```kotlin\ndependencies {\n implementation(\"androidx.compose.foundation:foundation:\u003cvar translate=\"no\"\u003eLATEST_COMPOSE_VERSION\u003c/var\u003e\")\n}\n\nandroid {\n buildFeatures {\n compose = true\n }\n\n composeOptions {\n kotlinCompilerExtensionVersion = \"\u003cvar translate=\"no\"\u003eLATEST_EXTENSION_VERSION\u003c/var\u003e\"\n }\n\n kotlinOptions {\n jvmTarget = \"\u003cvar translate=\"no\"\u003eLATEST_JVM_VERSION\u003c/var\u003e\"\n }\n}\n```\n\n### Groovy\n\n```groovy\ndependencies {\n implementation 'androidx.compose.foundation:foundation:\u003cvar translate=\"no\"\u003eLATEST_COMPOSE_VERSION\u003c/var\u003e'\n}\n\nandroid {\n buildFeatures {\n compose true\n }\n\n composeOptions {\n kotlinCompilerExtensionVersion = '\u003cvar translate=\"no\"\u003eLATEST_EXTENSION_VERSION\u003c/var\u003e'\n }\n\n kotlinOptions {\n jvmTarget = '\u003cvar translate=\"no\"\u003eLATEST_JVM_VERSION\u003c/var\u003e'\n }\n}\n```\n\n`TextField`\n-----------\n\nStylus handwriting is enabled for all `TextField` components by default on\nAndroid 14 and higher and the\n[`androidx.compose.foundation:foundation:1.7.0`](/jetpack/androidx/releases/compose-foundation)\ndependency. Handwriting mode is started for a `TextField` when a stylus motion\nevent is detected within the handwriting bounds of the component.\n\nThe handwriting bounds include 40 dp of vertical padding and 10 dp of horizontal\npadding around the input field.\n**Figure 2.** Handwriting bounds of `TextField` components.\n\nStylus handwriting is not supported for `TextField` fields when the input method\neditor is requested with [`KeyboardType.Password`](/reference/kotlin/androidx/compose/ui/text/input/KeyboardType#Password()).\n\nInput delegation\n----------------\n\nApps can display placeholder UI elements that appear to be text input fields but\nare actually just static UI elements with no text input capability. Search\nfields are a common example. Tapping the static UI element triggers a transition\nto a new UI that contains a functional text input field focused for input.\nYour browser doesn't support the video tag. **Figure 3.** Input delegation from static UI element to text input field.\n\n### Stylus input delegation\n\nUse the handwriting delegation APIs to support stylus handwriting input for\nplaceholder input fields (see [`handwritingDetector`](/reference/kotlin/androidx/compose/foundation/text/handwriting/package-summary#(androidx.compose.ui.Modifier).handwritingDetector(kotlin.Function0)) and\n[`handwritingHandler`](/reference/kotlin/androidx/compose/foundation/text/handwriting/package-summary#(androidx.compose.ui.Modifier).handwritingHandler())). The placeholder UI element is\nconfigured to delegate handwriting to a functional input field. For an example\nimplementation, see\n[`HandwritingDetectorSample.kt`](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/foundation/foundation/samples/src/main/java/androidx/compose/foundation/samples/HandwritingDetectorSample.kt).\n\nStylus handwriting mode starts when the functional input field gains focus and\ncreates an\n[`InputConnection`](/reference/kotlin/android/view/inputmethod/InputConnection).\nYour browser doesn't support the video tag. **Figure 4.** Stylus input delegation from static UI element to text input field.\n\nTesting\n-------\n\nStylus handwriting is supported on Android 14 and higher devices with a\ncompatible stylus input device and an [input method\neditor](/develop/ui/views/touch-and-input/creating-input-method) (IME) that\nsupports the Android 14 stylus handwriting APIs.\n\nIf you don't have a stylus input device, simulate stylus input on any device\nwith root access (including emulators) using the following Android Debug Bridge\n(adb) commands: \n\n\n // Android 14\n adb shell setprop persist.debug.input.simulate_stylus_with_touch true && adb shell stop && adb shell start\n\n // Android 15 and higher\n // Property takes effect after screen reconfiguration such as orientation change.\n adb shell setprop debug.input.simulate_stylus_with_touch true\n\nUse the Gboard beta for testing if you are using a device that doesn't support\nstylus.\n\nAdditional resources\n--------------------\n\n- Material Design --- [Text fields](https://m3.material.io/components/text-fields/overview)\n- [Handle user input](/develop/ui/compose/text/user-input)"]]