Я пытаюсь реализовать функцию чата в моем приложении. Я имею дело с элементами, которые выдвигаются вверх, когда называется клавиатура. Прямо сейчас то, что, кажется, работает наиболее близко к тому, что я хочу, это установить
android:windowSoftInputMode="adjustNothing", добавление imepadding и windownisset Поскольку я использую каркас .
Однако прокладка для блока чата перемещается, но не содержимое. Вместо этого я попытался использовать смещение Y, но я не совсем уверен, как получить высоту клавиатуры. < /P>
Box(
Modifier
.padding(top = 10.dp)
.fillMaxSize()
.consumeWindowInsets(padding)
.imePadding()
.zIndex(0.5f)
) {
var listState = rememberLazyListState()
val coroutineScope = rememberCoroutineScope()
var textBoxList = remember {
mutableStateListOf(
TextBoxData("This is the first message", "Bot"),
TextBoxData("This is the second message", "User"),
TextBoxData("This is the first message", "Bot"),
TextBoxData("This is the second message", "User"),
TextBoxData("This is the last message", "User")
)
}
// LazyColumn for chat
LazyColumn(
Modifier
.fillMaxSize()
.padding(bottom = 50.dp),
state = listState
) {
//For Each, Map
items(textBoxList) { item ->
TextBox(item)
}
}
// Bottom Input Bar
Box(
Modifier
.align(Alignment.BottomCenter)
.fillMaxWidth()
.height(50.dp)
.clip(RoundedCornerShape(20.dp))
.background(Black)
.border(2.dp, White, RoundedCornerShape(20.dp))
) {
Row(
Modifier.fillMaxSize(),
verticalAlignment = Alignment.CenterVertically
) {
Icon(
imageVector = FeatherIcons.Mic,
"Microphone Icon",
tint = White,
modifier = Modifier
.fillMaxHeight()
.padding(start = 10.dp)
)
// Text Field Here
var inputText by remember { mutableStateOf("") }
var textFieldScrollState = rememberScrollState(10)
var lineWidth = 255.dp
var textWidth = measureTextWidth(
inputText,
TextStyle(
fontSize = 16.sp,
fontFamily = RalewayRegular
)
)
// Configure the Alignment and Scroll State
TextField(
value = inputText,
onValueChange = {
inputText = it
val currLine = (textWidth / lineWidth).toInt()
coroutineScope.launch {
textFieldScrollState.scrollTo(
// Dont scroll if on first line (Default is 0)
if (currLine == 0) 5 else textFieldScrollState.maxValue - 5)
Log.i("TextSize", listState.layoutInfo.viewportEndOffset.toString())
}
},
placeholder = {
Text(
"Type Something...",
color = White.copy(0.7f),
fontSize = 16.sp,
lineHeight = 16.sp,
fontFamily = RalewayRegular
)
},
textStyle = TextStyle(
color = White,
fontSize = 16.sp,
fontFamily = RalewayRegular,
textAlign = TextAlign.Start,
),
modifier = Modifier
.width(290.dp)
.fillMaxHeight()
.padding(start = 10.dp)
.verticalScroll(textFieldScrollState),
colors = TextFieldDefaults.colors(
focusedTextColor = White,
unfocusedTextColor = White,
unfocusedContainerColor = Black,
focusedContainerColor = Black
)
)
val regex_space = Regex("^\\s*\$") // \\s* means unlimited number of empty (\\s)
Icon(
imageVector = FeatherIcons.Send,
contentDescription = "Send button",
tint = White,
modifier = Modifier
.fillMaxHeight()
.padding(start = 10.dp)
.clickable {
if (!inputText.matches(regex_space)) {
textBoxList.add(TextBoxData(inputText, "User"))
inputText = ""
//Use Coroutine Scope to Scroll
//LazyColumn needs items(textBoxList) to scroll to the item index
coroutineScope.launch {
listState.scrollToItem(textBoxList.size - 1)
}
}
}
)
}
}
}
}
Подробнее здесь: https://stackoverflow.com/questions/794 ... -is-called
Как прокрутить ленивый столбец, когда называется мягкая клавиатура? ⇐ Android
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Мягкая клавиатура открывает и закрывает прослушиватель в действии в Android
Anonymous » » в форуме Android - 0 Ответы
- 18 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Мягкая клавиатура открывает и закрывает прослушиватель в действии в Android
Anonymous » » в форуме Android - 0 Ответы
- 15 Просмотры
-
Последнее сообщение Anonymous
-