Google 致力于为黑人社区推动种族平等。查看具体举措

TextInputService

open class TextInputService
kotlin.Any
   ↳ androidx.compose.ui.text.input.TextInputService

Handles communication with the IME. Informs about the IME changes via EditCommands and provides utilities for working with software keyboard.

This class is responsible for ensuring there is only one open TextInputSession which will interact with software keyboards. Start new a TextInputSession by calling startInput and close it with stopInput.

Summary

Public constructors
<init>(platformTextInputService: PlatformTextInputService)

Handles communication with the IME.

Public methods
Unit

Hide onscreen keyboard.

Unit

Request showing onscreen keyboard.

open TextInputSession
startInput(value: TextFieldValue, imeOptions: ImeOptions, onEditCommand: (List<EditCommand>) -> Unit, onImeActionPerformed: (ImeAction) -> Unit)

Start text input session for given client.

open Unit

Stop text input session.

Public constructors

<init>

TextInputService(platformTextInputService: PlatformTextInputService)

Handles communication with the IME. Informs about the IME changes via EditCommands and provides utilities for working with software keyboard.

This class is responsible for ensuring there is only one open TextInputSession which will interact with software keyboards. Start new a TextInputSession by calling startInput and close it with stopInput.

Public methods

hideSoftwareKeyboard

fun hideSoftwareKeyboard(): Unit

Hide onscreen keyboard.

showSoftwareKeyboard

fun showSoftwareKeyboard(): Unit

Request showing onscreen keyboard.

This call will be ignored if there is not an open TextInputSession, as it means there is nothing that will accept typed input. The most common way to open a TextInputSession is to set the focus to an editable text composable.

There is no guarantee that the keyboard will be shown. The software keyboard or system service may silently ignore this request.

startInput

open fun startInput(
    value: TextFieldValue,
    imeOptions: ImeOptions,
    onEditCommand: (List<EditCommand>) -> Unit,
    onImeActionPerformed: (ImeAction) -> Unit
): TextInputSession

Start text input session for given client.

If there is a previous TextInputSession open, it will immediately be closed by this call to startInput.

Parameters
value: TextFieldValue initial TextFieldValue
imeOptions: ImeOptions IME configuration
onEditCommand: (List<EditCommand>) -> Unit callback to inform about changes requested by IME
onImeActionPerformed: (ImeAction) -> Unit callback to inform if an IME action such as ImeAction.Done etc occurred.

stopInput

open fun stopInput(session: TextInputSession): Unit

Stop text input session.

If the session is not the currently open session, no action will occur.

Parameters
session: TextInputSession the session returned by startInput call.