如何在 Jetpack Compose 中制作迷你工厂

问题描述 投票:0回答:3
android android-jetpack-compose floating-action-button
3个回答
4
投票

如果您的项目中使用了

androidx.compose.material3
,则可以使用
SmallFloatingActionButton

@Composable
public fun SmallFloatingActionButton(
    onClick: () → Unit,
    modifier: Modifier,
    interactionSource: MutableInteractionSource,
    shape: Shape,
    containerColor: Color,
    contentColor: Color,
    elevation: FloatingActionButtonElevation,
    content: @Composable
() → Unit
): Unit

3
投票

正如您在 FAB 实现中所看到的,它设置了默认大小。 如果你想改变FAB的大小,我认为唯一的方法是使用

Modifier.size(40.dp)

FloatingActionButton(
    modifier = Modifier.size(40.dp), // 40 is a mini-fab
    onClick = {  }
) {
    Icon(imageVector = Icons.Filled.Add, contentDescription = null)
}

0
投票

在 Compose 中,您现在可以使用材质 3 来使用

SmallFloatingActionButton
:示例:

@Composable
fun SmallExample(onClick: () -> Unit) {
    SmallFloatingActionButton(
        onClick = { onClick() },
        containerColor = MaterialTheme.colorScheme.secondaryContainer,
        contentColor = MaterialTheme.colorScheme.secondary
    ) {
        Icon(Icons.Filled.Add, "Example test")
    }
}

您可以了解更多信息:https://developer.android.com/jetpack/compose/components/fab#small

© www.soinside.com 2019 - 2024. All rights reserved.