android 更改Material3分隔线中的起始缩进

4sup72z8  于 2023-01-07  发布在  Android
关注(0)|答案(2)|浏览(183)

androidx. composite.material 中,分割线组件定义为:

@Composable
fun Divider(
    modifier: Modifier = Modifier,
    color: Color = MaterialTheme.colors.onSurface.copy(alpha = DividerAlpha),
    thickness: Dp = 1.dp,
    startIndent: Dp = 0.dp
): Unit

androidx.compose.material3 中,分割线组件定义为:

@Composable
fun Divider(
    modifier: Modifier = Modifier,
    thickness: Dp = DividerDefaults.Thickness,
    color: Color = DividerDefaults.color
): Unit

如何在新版本中更改startIndent?

g9icjywg

g9icjywg1#

startIndent是利用Modifier.padding(start = startIndent)实现的简单起始偏移。
可以简单地应用padding修改器:

androidx.compose.material3.Divider(
    modifier = Modifier.padding(start = 10.dp),
)
wpcxdonn

wpcxdonn2#

Divider只是带有一些修饰符的Box
您可以创建自己的Divider,类似于材质提供的分隔符:

@Composable
fun CustomDivider(
    modifier: Modifier = Modifier,
    thickness: Dp = DividerDefaults.Thickness,
    color: Color = DividerDefaults.color,
    startIndent: Dp = 0.dp,
) {
    val targetThickness = if (thickness == Dp.Hairline) {
        (1f / LocalDensity.current.density).dp
    } else {
        thickness
    }
    Box(
        modifier
            .fillMaxWidth()
            .padding(start = startIndent)
            .height(targetThickness)
            .background(color = color)
    )
}

相关问题