Получить выбранное количество текста в BasicTextFieldAndroid

Форум для тех, кто программирует под Android
Ответить
Anonymous
 Получить выбранное количество текста в BasicTextField

Сообщение Anonymous »


I want to get BasicTextField selected text count in jetpack-compose, how can I do it? I want to check if any text is selected in the BasicTextField, show a dialog.

CustomBasicTextField( value = uiState.note.title, updateTextValue = { viewModel.updateNote(uiState.note.copy(title = it)) }, textStyle = MaterialTheme.typography.headlineSmall.copy(fontSize = 20.sp), placeholder = "Enter title", keyboardOptions = KeyboardOptions(imeAction = ImeAction.Done), ) @Composable fun CustomBasicTextField( modifier: Modifier = Modifier, readOnly: Boolean = false, value: String, height: Dp = 54.dp, borderWidth: Dp = 1.dp, borderColor: Color = Color.Unspecified, borderShape: Shape = RoundedCornerShape(size = 5.dp), updateTextValue: (String) -> Unit, textStyle: TextStyle = TextStyle( fontSize = 16.sp, fontWeight = FontWeight.Medium, color = Color.DarkGray ), contentAlignment: Alignment = Alignment.CenterStart, visualTransformation: VisualTransformation = VisualTransformation.None, keyboardOptions: KeyboardOptions = KeyboardOptions.Default, keyboardActions: KeyboardActions = KeyboardActions.Default, singleLine: Boolean = false, label: @Composable (() -> Unit)? = null, placeholder: String = "", leadingIcon: @Composable (() -> Unit)? = null, trailingIcon: @Composable (() -> Unit)? = null, ) { Column(modifier = modifier.height(height)) { label?.let { it() } BasicTextField( modifier = modifier.fillMaxSize(), readOnly = readOnly, value = value, onValueChange = { newText -> updateTextValue(newText) }, visualTransformation = visualTransformation, keyboardActions = keyboardActions, keyboardOptions = keyboardOptions, singleLine = singleLine, textStyle = textStyle, decorationBox = { innerTextField -> Box( modifier = Modifier .fillMaxSize() .border( width = borderWidth, color = borderColor, shape = borderShape ) .padding(horizontal = 16.dp, vertical = 8.dp), contentAlignment = contentAlignment // Center the content vertically ) { Row( modifier = Modifier.fillMaxWidth(), verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(4.dp) ) { leadingIcon?.let { it() } Box( modifier = Modifier .weight(1f) ) { if (value.isEmpty()) { Text( text = placeholder, style = LocalTextStyle.current.copy( fontSize = 16.sp, color = MaterialTheme.colorScheme.outline ), ) } innerTextField() } trailingIcon?.let { it() } } } } ) } } i tried this but not working:"https://stackoverflow.com/questions/686 ... ncontainer"


Источник: https://stackoverflow.com/questions/780 ... ctextfield
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Android»