跳转至

FloatingActionButton

@OptIn(markerClass = [ExperimentalMaterialApi])
@Composable
fun FloatingActionButton(
    onClick: () -> Unit,
    modifier: Modifier = Modifier,
    interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
    shape: Shape = MaterialTheme.shapes.small.copy(CornerSize(percent = 50)),
    backgroundColor: Color = MaterialTheme.colors.secondary,
    contentColor: Color = contentColorFor(backgroundColor),
    elevation: FloatingActionButtonElevation = FloatingActionButtonDefaults.elevation(),
    content: () -> Unit
): @OptIn(markerClass = [ExperimentalMaterialApi]) @Composable Unit

1. 概述

Material Design floating action button

一个 FloatActionButton(FAB)代表一个屏幕的主要行为。

FAB 通常和一个 Icon 一起使用

import androidx.compose.material.FloatingActionButton
import androidx.compose.material.Icon

FloatingActionButton(onClick = { /*do something*/ }) {
    Icon(Icons.Filled.Favorite, contentDescription = "Localized description")
}

可以查阅 ExtendedFloatingActionButton,它是一个包含文本和可选图标的扩展 FAB


最后更新: July 15, 2021