按钮宽度调整:
实现按钮宽度规则:默认 140dp,只有内容宽度超过 140dp 时直接扩展到 250dp。
This commit is contained in:
@@ -35,8 +35,11 @@ import androidx.compose.ui.graphics.Brush
|
|||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.layout.ContentScale
|
import androidx.compose.ui.layout.ContentScale
|
||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
|
import androidx.compose.ui.platform.LocalDensity
|
||||||
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
|
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
|
||||||
import androidx.compose.ui.res.stringResource
|
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.dp
|
||||||
import androidx.compose.ui.unit.sp
|
import androidx.compose.ui.unit.sp
|
||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
@@ -566,10 +569,27 @@ fun AddAgentScreen() {
|
|||||||
.padding(horizontal = 16.dp)
|
.padding(horizontal = 16.dp)
|
||||||
.align(Alignment.Start)
|
.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(
|
Box(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.align(Alignment.Start)
|
.align(Alignment.Start)
|
||||||
.widthIn(min = 140.dp,max = 250.dp)
|
.width(boxWidth)
|
||||||
.height(40.dp)
|
.height(40.dp)
|
||||||
.shadow(
|
.shadow(
|
||||||
elevation = 10.dp,
|
elevation = 10.dp,
|
||||||
@@ -617,7 +637,7 @@ fun AddAgentScreen() {
|
|||||||
)
|
)
|
||||||
Spacer(modifier = Modifier.width(8.dp))
|
Spacer(modifier = Modifier.width(8.dp))
|
||||||
Text(
|
Text(
|
||||||
text = stringResource(R.string.create_agent_auto),
|
text = autoLabel,
|
||||||
color = appColors.text,
|
color = appColors.text,
|
||||||
fontWeight = FontWeight.W600,
|
fontWeight = FontWeight.W600,
|
||||||
fontSize = 14.sp
|
fontSize = 14.sp
|
||||||
|
|||||||
@@ -214,7 +214,7 @@ fun NewsCommentModal(
|
|||||||
verticalAlignment = Alignment.CenterVertically
|
verticalAlignment = Alignment.CenterVertically
|
||||||
) {
|
) {
|
||||||
Text(
|
Text(
|
||||||
text = "${currentCommentCount}条评论",
|
text = stringResource(R.string.comment_count, currentCommentCount),
|
||||||
fontSize = 15.sp,
|
fontSize = 15.sp,
|
||||||
fontWeight = FontWeight.Bold,
|
fontWeight = FontWeight.Bold,
|
||||||
color = AppColors.text
|
color = AppColors.text
|
||||||
|
|||||||
Reference in New Issue
Block a user