{% setvar book_path %}/reference/androidx/_book.yaml{% endsetvar %} {% include "_shared/_reference-head-tags.html" %}

TextInputService

public class 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

TextInputService(
    @NonNull PlatformTextInputService platformTextInputService
)

Public methods

final void

This method is deprecated. Use SoftwareKeyboardController.hide or TextInputSession.hideSoftwareKeyboard instead.

final void

This method is deprecated. Use SoftwareKeyboardController.show or TextInputSession.showSoftwareKeyboard instead.

@NonNull TextInputSession
startInput(
    @NonNull TextFieldValue value,
    @NonNull ImeOptions imeOptions,
    @NonNull Function1<@NonNull List<@NonNull EditCommand>, Unit> onEditCommand,
    @NonNull Function1<@NonNull ImeActionUnit> onImeActionPerformed
)

Start text input session for given client.

void

Stop text input session.

Public constructors

TextInputService

public TextInputService(
    @NonNull PlatformTextInputService platformTextInputService
)

Public methods

hideSoftwareKeyboard

public final void hideSoftwareKeyboard()

Hide onscreen keyboard.

showSoftwareKeyboard

public final void showSoftwareKeyboard()

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

public @NonNull TextInputSession startInput(
    @NonNull TextFieldValue value,
    @NonNull ImeOptions imeOptions,
    @NonNull Function1<@NonNull List<@NonNull EditCommand>, Unit> onEditCommand,
    @NonNull Function1<@NonNull ImeActionUnit> onImeActionPerformed
)

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
@NonNull TextFieldValue value

initial TextFieldValue

@NonNull ImeOptions imeOptions

IME configuration

@NonNull Function1<@NonNull List<@NonNull EditCommand>, Unit> onEditCommand

callback to inform about changes requested by IME

@NonNull Function1<@NonNull ImeActionUnit> onImeActionPerformed

callback to inform if an IME action such as ImeAction.Done etc occurred.

stopInput

public void stopInput(@NonNull TextInputSession session)

Stop text input session.

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

Parameters
@NonNull TextInputSession session

the session returned by startInput call.