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

TextInputSession

public final class TextInputSession


Represents a input session for interactions between a soft keyboard and editable text.

This session may be closed at any time by TextInputService or by calling dispose, after which isOpen will return false and all further calls will have no effect.

Summary

Public constructors

TextInputSession(
    @NonNull TextInputService textInputService,
    @NonNull PlatformTextInputService platformTextInputService
)

Public methods

final void

Close this input session.

final boolean

Hide onscreen keyboard for a specific TextInputSession.

final boolean

If this session is currently open.

final boolean

Notify the focused rectangle to the system.

final boolean

Request showing onscreen keyboard.

final boolean

Notify IME about the new TextFieldValue and latest state of the editing buffer.

Public constructors

TextInputSession

public TextInputSession(
    @NonNull TextInputService textInputService,
    @NonNull PlatformTextInputService platformTextInputService
)

Public methods

dispose

public final void dispose()

Close this input session.

All further calls to this object will have no effect, and isOpen will return false.

Note, TextInputService may also close this input session at any time without calling dispose. Calling dispose after this session has been closed has no effect.

hideSoftwareKeyboard

public final boolean hideSoftwareKeyboard()

Hide onscreen keyboard for a specific TextInputSession.

This call will have no effect if this session is not open.

This should be used instead of TextInputService.showSoftwareKeyboard when implementing a new editable text composable to hide the keyboard in response to events related to that composable.

Returns
boolean

false if this session expired and no action was performed

isOpen

public final boolean isOpen()

If this session is currently open.

A session may be closed at any time by TextInputService or by calling dispose.

notifyFocusedRect

public final boolean notifyFocusedRect(@NonNull Rect rect)

Notify the focused rectangle to the system.

The system can ignore this information or use it to for additional functionality.

For example, desktop systems show a popup near the focused input area (for some languages).

If the session is not open, no action will be performed.

Parameters
@NonNull Rect rect

the rectangle that describes the boundaries on the screen that requires focus

Returns
boolean

false if this session expired and no action was performed

showSoftwareKeyboard

public final boolean showSoftwareKeyboard()

Request showing onscreen keyboard.

This call will have no effect if this session is not open.

This should be used instead of TextInputService.showSoftwareKeyboard when implementing a new editable text composable to show the keyboard in response to events related to that composable.

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

Returns
boolean

false if this session expired and no action was performed

updateState

public final boolean updateState(TextFieldValue oldValue, @NonNull TextFieldValue newValue)

Notify IME about the new TextFieldValue and latest state of the editing buffer. oldValue is the state of the buffer before the changes applied by the newValue.

oldValue represents the changes that was requested by IME on the buffer, and newValue is the final state of the editing buffer that was requested by the application. In cases where oldValue is not equal to newValue, it would mean the IME suggested value is rejected, and the IME connection will be restarted with the newValue.

If the session is not open, action will be performed.

Parameters
TextFieldValue oldValue

the value that was requested by IME on the buffer

@NonNull TextFieldValue newValue

final state of the editing buffer that was requested by the application

Returns
boolean

false if this session expired and no action was performed