Освой Android играючи

Сайт Александра Климова

Шкодим

/* Моя кошка замечательно разбирается в программировании. Стоит мне объяснить проблему ей - и все становится ясно. */
John Robbins, Debugging Applications, Microsoft Press, 2000

Compose: TextField

10-й курс/Закрытая зона

Обновлено 31 июля 2023, 20 февраля 2024, 2 мая 2024

TextField

Функция TextField позволяет создать стандартное текстовое поле для ввода текста, знакомое нам по EditText.

Определение функции.


// Material 3
@OptIn(markerClass = {androidx.compose.material3.ExperimentalMaterial3Api::class})
@Composable
public fun TextField(
    value: String,
    onValueChange: (String) -> Unit,
    modifier: Modifier = Modifier,
    enabled: Boolean = true,
    readOnly: Boolean = false,
    textStyle: TextStyle = LocalTextStyle.current,
    label: @Composable() (() -> Unit)? = null,
    placeholder: @Composable() (() -> Unit)? = null,
    leadingIcon: @Composable() (() -> Unit)? = null,
    trailingIcon: @Composable() (() -> Unit)? = null,
    prefix: @Composable() (() -> Unit)? = null,
    suffix: @Composable() (() -> Unit)? = null,
    supportingText: @Composable() (() -> Unit)? = null,
    isError: Boolean = false,
    visualTransformation: VisualTransformation = VisualTransformation.None,
    keyboardOptions: KeyboardOptions = KeyboardOptions.Default,
    keyboardActions: KeyboardActions = KeyboardActions.Default,
    singleLine: Boolean = false,
    maxLines: Int = if (singleLine) 1 else Int.MAX_VALUE,
    minLines: Int = 1,
    interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
    shape: Shape = TextFieldDefaults.shape,
    colors: TextFieldColors = TextFieldDefaults.colors()
): Unit

// Material 2
@Composable
public fun TextField(
    value: TextFieldValue,
    onValueChange: (TextFieldValue) → Unit,
    modifier: Modifier,
    enabled: Boolean,
    readOnly: Boolean,
    textStyle: TextStyle,
    label: @Composable()
(() → Unit)?,
    placeholder: @Composable()
(() → Unit)?,
    leadingIcon: @Composable()
(() → Unit)?,
    trailingIcon: @Composable()
(() → Unit)?,
    isError: Boolean,
    visualTransformation: VisualTransformation,
    keyboardOptions: KeyboardOptions,
    keyboardActions: KeyboardActions,
    singleLine: Boolean,
    maxLines: Int,
    interactionSource: MutableInteractionSource,
    shape: Shape,
    colors: TextFieldColors
): Unit

В версии Compose 1.4 у компонентов TextField, BasicTextField, OutlinedTextField появился новый параметр minLines.

Вы вошли на сайт, как гость.
Необходимо зарегистрироваться, чтобы прочитать статью

Реклама