Jetpack Compose中,如果文本过长,图标可能会消失。

5
@Composable
fun TopAppBar(
    name: String,
    modifier: Modifier = Modifier
) {
    Row(
        modifier = modifier
            .fillMaxWidth()
            .padding(20.dp, 0.dp),
        verticalAlignment = Alignment.CenterVertically,
        horizontalArrangement = Arrangement.SpaceBetween
    ) {
        Icon(
            imageVector = Icons.Default.ArrowBack,
            contentDescription = "Back",
            tint = Color.Black,
            modifier = Modifier.size(24.dp)
        )
        Text(
            text = name,
            overflow = TextOverflow.Ellipsis,
            fontWeight = FontWeight.Bold,
            fontSize = 20.sp,
            maxLines = 1
        )

        Row {
            Icon(
                painter = painterResource(id = R.drawable.ic_bell),
                contentDescription = null,
                tint = Color.Black,
                modifier = Modifier
                    .padding(8.dp, 8.dp)
                    .size(24.dp)
            )
            Icon(
                painter = painterResource(id = R.drawable.ic_dotmenu),
                contentDescription = null,
                tint = Color.Black,
                modifier = Modifier
                    .padding(8.dp, 8.dp)
                    .size(24.dp)
            )
        }

    }
}

enter image description here

2个回答

3

您需要将weightfill设置为false

    Text(
        modifier = Modifier.weight(weight = 1f, fill = false),
        text = name,
        overflow = TextOverflow.Ellipsis,
        fontWeight = FontWeight.Bold,
        fontSize = 20.sp,
        maxLines = 1
    )

Result


2
你可以在 Text 组合中添加 weight 修饰符。
Row(){
    Icon()
    Text(
        text = ".....",
        overflow = TextOverflow.Ellipsis,
        fontWeight = FontWeight.Bold,
        fontSize = 20.sp,
        maxLines = 1,
        modifier = Modifier.weight(1f)
    )
    //...
}

enter image description here. enter image description here


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接