У меня проблемы с размером кнопок на экране. Я хочу, чтобы кнопки имели одинаковый размер и занимали все доступное пространство. Когда я запускаю приведенный ниже код, кнопки заполняют всю ширину, но не высоту, а также их размеры не равны (когда один ActionButton имеет более длинный текст, чем другие). Почему?
Я уже пытался разместить разделители между кнопками, чтобы автоматически разделить их, но они не увеличивали другие кнопки и не выравнивали их расстояние. Я также обнаружил, что не могу использовать Modifier.weight для кнопок, что странно, поскольку они находятся в столбце.
@Composable
fun ActionButton(ButtonText: String, ButtonColor: Color,) {
Button(
onClick = { /*TODO*/ },
enabled = true,
colors = ButtonColors(
containerColor = ButtonColor,
contentColor = Color.White,
disabledContainerColor = Color.Gray, //TODO: Look into this later
disabledContentColor = Color.LightGray
),
modifier = Modifier
.fillMaxWidth()
.padding(18.dp)
) {
Text(
text = ButtonText,
style = MaterialTheme.typography.displaySmall)
}
}
data class ActionButtonData(val ButtonText: String, val ButtonColor: Color)
@Composable
fun ActionButtonColumn(){
val ActionButtonsValues = listOf(
ActionButtonData("Call 911", MaterialTheme.colorScheme.primary),
ActionButtonData("Text 911", MaterialTheme.colorScheme.secondary),
ActionButtonData("SOS", MaterialTheme.colorScheme.tertiary)
)
Column (
horizontalAlignment = androidx.compose.ui.Alignment.CenterHorizontally,
modifier = Modifier
.fillMaxSize()
) {
ActionButtonsValues.forEach {
ActionButton(ButtonText = it.ButtonText, ButtonColor = it.ButtonColor)
}
}
}
Подробнее здесь: https://stackoverflow.com/questions/793 ... ck-compose