Tulis tangan stilus diaktifkan untuk semua komponen TextField secara default aktif
Android 14 dan yang lebih baru, serta
androidx.compose.foundation:foundation:1.7.0
dependensi. Mode tulis tangan dimulai untuk TextField saat gerakan stilus
terdeteksi dalam batas tulisan tangan komponen.
Batas tulisan tangan mencakup padding vertikal 40 dp dan horizontal 10 dp
{i>padding<i} di sekitar bidang input.
Gambar 2. Batas tulisan tangan dari komponen TextField.
Tulis tangan stilus tidak didukung untuk kolom TextField saat metode input
editor diminta dengan KeyboardType.Password.
Delegasi input
Aplikasi dapat menampilkan elemen UI placeholder yang tampak seperti kolom input teks tetapi
sebenarnya hanyalah elemen UI statis tanpa kemampuan {i>input <i}teks. Telusuri
{i>field<i} adalah contoh umumnya. Mengetuk elemen UI statis akan memicu transisi
ke UI baru yang berisi kolom input teks fungsional yang difokuskan untuk input.
Gambar 3. Delegasi input dari elemen UI statis ke kolom input teks.
Delegasi input stilus
Gunakan API delegasi tulisan tangan untuk mendukung input tulis tangan stilus untuk
kolom input placeholder (lihat handwritingDetector dan
handwritingHandler) Elemen UI placeholder adalah
dikonfigurasi untuk mendelegasikan tulisan tangan ke bidang input yang berfungsi. Untuk contoh
implementasi, lihat
HandwritingDetectorSample.kt
Mode tulis tangan stilus dimulai saat bidang input fungsional mendapatkan fokus dan
membuat
InputConnection
Gambar 4. Delegasi input stilus dari elemen UI statis ke kolom input teks.
Pengujian
Tulis tangan stilus didukung di perangkat Android 14 dan yang lebih tinggi dengan
perangkat input stilus yang kompatibel dan metode input
(IME) yang
mendukung API tulis tangan stilus Android 14.
Jika Anda tidak memiliki perangkat input stilus, simulasikan input stilus di perangkat apa pun
dengan akses root (termasuk emulator) menggunakan Android Debug Bridge berikut
(adb):
Konten dan contoh kode di halaman ini tunduk kepada lisensi yang dijelaskan dalam Lisensi Konten. Java dan OpenJDK adalah merek dagang atau merek dagang terdaftar dari Oracle dan/atau afiliasinya.
Terakhir diperbarui pada 2025-07-27 UTC.
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Informasi yang saya butuhkan tidak ada","missingTheInformationINeed","thumb-down"],["Terlalu rumit/langkahnya terlalu banyak","tooComplicatedTooManySteps","thumb-down"],["Sudah usang","outOfDate","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Masalah kode / contoh","samplesCodeIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 2025-07-27 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)"]]