按钮宽度调整:

实现按钮宽度规则:默认 140dp,只有内容宽度超过 140dp 时直接扩展到 250dp。
This commit is contained in:
2025-11-17 18:10:53 +08:00
parent 2f8cc8832a
commit bec33c165e
2 changed files with 23 additions and 3 deletions

View File

@@ -35,8 +35,11 @@ import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.rememberTextMeasurer
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.lifecycle.viewModelScope
@@ -566,10 +569,27 @@ fun AddAgentScreen() {
.padding(horizontal = 16.dp)
.align(Alignment.Start)
) {
val density = LocalDensity.current
val textMeasurer = rememberTextMeasurer()
val autoLabel = stringResource(R.string.create_agent_auto)
val measuredTextWidth = remember(autoLabel, textMeasurer) {
textMeasurer.measure(
text = AnnotatedString(autoLabel),
style = TextStyle(
color = appColors.text,
fontWeight = FontWeight.W600,
fontSize = 14.sp
)
).size.width
}
val textWidthDp = with(density) { measuredTextWidth.toDp() }
val contentWidth = 24.dp + 18.dp + 8.dp + textWidthDp
val boxWidth = if (contentWidth > 140.dp) 250.dp else 140.dp
Box(
modifier = Modifier
.align(Alignment.Start)
.widthIn(min = 140.dp,max = 250.dp)
.width(boxWidth)
.height(40.dp)
.shadow(
elevation = 10.dp,
@@ -617,7 +637,7 @@ fun AddAgentScreen() {
)
Spacer(modifier = Modifier.width(8.dp))
Text(
text = stringResource(R.string.create_agent_auto),
text = autoLabel,
color = appColors.text,
fontWeight = FontWeight.W600,
fontSize = 14.sp

View File

@@ -214,7 +214,7 @@ fun NewsCommentModal(
verticalAlignment = Alignment.CenterVertically
) {
Text(
text = "${currentCommentCount}条评论",
text = stringResource(R.string.comment_count, currentCommentCount),
fontSize = 15.sp,
fontWeight = FontWeight.Bold,
color = AppColors.text