---
title: 悬浮操作按钮
description: 遵循 Material Design 3 的 Jetpack Compose 悬浮操作按钮组件。
sourceCodeUrl: 'https://github.com/expo/expo/tree/sdk-57/packages/expo-ui'
packageName: '@expo/ui'
platforms: ['android', 'expo-go']
---

This documentation is available as Markdown for AI agents and LLMs. See the [full Markdown index](https://docs.expo.dev/llms.txt) or append .md to any documentation URL.

# 悬浮操作按钮

遵循 Material Design 3 的 Jetpack Compose 悬浮操作按钮组件。

<AgentInstructions>

## Submitting Feedback

If you encounter errors, misleading or outdated information, report it so Expo can be improved:

Preferred command:
npx --yes submit-expo-feedback@latest --category docs --subject "/versions/latest/sdk/ui/jetpack-compose/floatingactionbutton/" "<actionable feedback>"

Direct HTTP fallback:
curl -X POST https://api.expo.dev/v2/feedback/docs-send -H 'Content-Type: application/json' -d '{"url":"/versions/latest/sdk/ui/jetpack-compose/floatingactionbutton/","feedback":"🤖 Agent feedback for docs: <specific, actionable description> (<model>, <harness>)"}'

Only submit when you have something specific and actionable to report. Try to give the most context.

## Navigation

When answering a related or follow-up question, use llms.txt to find the relevant page as Markdown (.md) instead of guessing.

You are here: Reference (v57.0.0) > Expo UI > Jetpack Compose (51 pages in this section)
Full documentation tree: [llms.txt](https://docs.expo.dev/llms.txt)

</AgentInstructions>
Android, Included in Expo Go

Expo UI 提供四种 FloatingActionButton 变体，与 Material Design 3 [`FloatingActionButton`](https://developer.android.com/develop/ui/compose/components/fab) API 相匹配：

-   `SmallFloatingActionButton` — 紧凑型 FAB
-   `FloatingActionButton` — 标准 FAB（默认大小）
-   `LargeFloatingActionButton` — 更大的 FAB
-   `ExtendedFloatingActionButton` — 带图标和文本标签的 FAB，支持动画展开/收起

每个组件都使用基于插槽的子组件（`.Icon`，以及对于 `ExtendedFloatingActionButton` 的 `.Text`）来组合内容。

> **注意：** 如果你需要在浮动工具栏中放置多个操作按钮，请改用 [`HorizontalFloatingToolbar`](https://docs.expo.dev/versions/latest/sdk/ui/jetpack-compose/horizontalfloatingtoolbar.md)。

Image: 小号、标准和大号 Material 3 浮动操作按钮

## 安装

```sh
# npm
npx expo install @expo/ui

# yarn
yarn expo install @expo/ui

# pnpm
pnpm expo install @expo/ui

# bun
bun expo install @expo/ui
```

If you are installing this in an [existing React Native app](https://docs.expo.dev/bare/overview.md), make sure to [install `expo`](https://docs.expo.dev/bare/installing-expo-modules.md) in your project.

## 用法

### 标准 FloatingActionButton

```tsx StandardFABExample.tsx
import {
  FloatingActionButton,
  Host,
  Icon,
} from '@expo/ui/jetpack-compose';

export default function StandardFABExample() {
  return (
    <Host matchContents>
      <FloatingActionButton
        onClick={() => console.log('FAB pressed')}>
        <FloatingActionButton.Icon>
          <Icon source={require('./assets/add.xml')} />
        </FloatingActionButton.Icon>
      </FloatingActionButton>
    </Host>
  );
}
```

### FAB 变体

```tsx FABVariantsExample.tsx
import {
  FloatingActionButton,
  Host,
  Icon,
  LargeFloatingActionButton,
  SmallFloatingActionButton,
} from '@expo/ui/jetpack-compose';
import { View } from 'react-native';

export default function FABVariantsExample() {
  return (
    <View style={{ flexDirection: 'row', gap: 16 }}>
      <Host matchContents>
        <SmallFloatingActionButton onClick={() => {}}>
          <SmallFloatingActionButton.Icon>
            <Icon source={require('./assets/add.xml')} />
          </SmallFloatingActionButton.Icon>
        </SmallFloatingActionButton>
      </Host>
      <Host matchContents>
        <FloatingActionButton onClick={() => {}}>
          <FloatingActionButton.Icon>
            <Icon source={require('./assets/add.xml')} />
          </FloatingActionButton.Icon>
        </FloatingActionButton>
      </Host>
      <Host matchContents>
        <LargeFloatingActionButton onClick={() => {}}>
          <LargeFloatingActionButton.Icon>
            <Icon source={require('./assets/add.xml')} />
          </LargeFloatingActionButton.Icon>
        </LargeFloatingActionButton>
      </Host>
    </View>
  );
}
```

### ExtendedFloatingActionButton

```tsx ExtendedFABExample.tsx
import {
  ExtendedFloatingActionButton,
  Host,
  Icon,
  Text,
} from '@expo/ui/jetpack-compose';
import { useState } from 'react';

export default function ExtendedFABExample() {
  const [expanded, setExpanded] = useState(true);

  return (
    <Host matchContents>
      <ExtendedFloatingActionButton
        expanded={expanded}
        onClick={() => setExpanded(v => !v)}>
        <ExtendedFloatingActionButton.Icon>
          <Icon source={require('./assets/edit.xml')} />
        </ExtendedFloatingActionButton.Icon>
        <ExtendedFloatingActionButton.Text>
          <Text>编辑</Text>
        </ExtendedFloatingActionButton.Text>
      </ExtendedFloatingActionButton>
    </Host>
  );
}
```

### 悬浮于内容上方

使用带有 `align('bottomEnd')` 的 Compose `Box`，即可将 FAB 放置在可滚动内容之上，并且完全位于 Compose 层内。

```tsx FloatingFABExample.tsx
import {
  Box,
  FloatingActionButton,
  Host,
  Icon,
  LazyColumn,
  ListItem,
  Text,
} from '@expo/ui/jetpack-compose';
import {
  align,
  fillMaxSize,
  offset,
} from '@expo/ui/jetpack-compose/modifiers';

const ITEMS = Array.from(
  { length: 20 },
  (_, index) => `Item ${index + 1}`
);

export default function FloatingFABExample() {
  return (
    <Host style={{ flex: 1 }}>
      <Box modifiers={[fillMaxSize()]}>
        <LazyColumn modifiers={[fillMaxSize()]}>
          {ITEMS.map(item => (
            <ListItem key={item}>
              <ListItem.HeadlineContent>
                <Text>{item}</Text>
              </ListItem.HeadlineContent>
            </ListItem>
          ))}
        </LazyColumn>

        <FloatingActionButton
          modifiers={[align('bottomEnd'), offset(-16, -16)]}
          onClick={() => console.log('pressed')}>
          <FloatingActionButton.Icon>
            <Icon source={require('./assets/add.xml')} />
          </FloatingActionButton.Icon>
        </FloatingActionButton>
      </Box>
    </Host>
  );
}
```

### 自定义颜色

```tsx FABCustomColorExample.tsx
import {
  ExtendedFloatingActionButton,
  Host,
  Icon,
  Text,
} from '@expo/ui/jetpack-compose';

export default function FABCustomColorExample() {
  return (
    <Host matchContents>
      <ExtendedFloatingActionButton
        containerColor="#E8DEF8"
        onClick={() => console.log('pressed')}>
        <ExtendedFloatingActionButton.Icon>
          <Icon source={require('./assets/add.xml')} />
        </ExtendedFloatingActionButton.Icon>
        <ExtendedFloatingActionButton.Text>
          <Text>新项目</Text>
        </ExtendedFloatingActionButton.Text>
      </ExtendedFloatingActionButton>
    </Host>
  );
}
```

## API

```tsx
import {
  SmallFloatingActionButton,
  FloatingActionButton,
  LargeFloatingActionButton,
  ExtendedFloatingActionButton,
} from '@expo/ui/jetpack-compose';
```

## Components

### `ExtendedFloatingActionButton`

Supported platforms: Android.

Type: React.[Element](https://www.typescriptlang.org/docs/handbook/jsx.html#function-component)<[ExtendedFloatingActionButtonProps](https://docs.expo.dev/versions/latest/sdk/ui/jetpack-compose/floatingactionbutton.md#extendedfloatingactionbuttonprops)\>

Renders a Material Design 3 `ExtendedFloatingActionButton` with animated label expansion.

Wraps [`ExtendedFloatingActionButton`](https://developer.android.com/reference/kotlin/androidx/compose/material3/package-summary#ExtendedFloatingActionButton\(kotlin.Function0,androidx.compose.ui.Modifier,androidx.compose.ui.graphics.Shape,androidx.compose.ui.graphics.Color,androidx.compose.ui.graphics.Color,androidx.compose.material3.FloatingActionButtonElevation,androidx.compose.foundation.interaction.MutableInteractionSource,kotlin.Function1\)).

Example

```tsx
import { ExtendedFloatingActionButton, Host, Icon, Text } from '@expo/ui/jetpack-compose';

<Host matchContents>
  <ExtendedFloatingActionButton expanded={true} onClick={() => console.log('pressed')}>
    <ExtendedFloatingActionButton.Icon>
      <Icon source={require('./assets/edit.xml')} />
    </ExtendedFloatingActionButton.Icon>
    <ExtendedFloatingActionButton.Text>
      <Text>Edit</Text>
    </ExtendedFloatingActionButton.Text>
  </ExtendedFloatingActionButton>
</Host>
```

Props for the `ExtendedFloatingActionButton` component.

ExtendedFloatingActionButtonProps

### `children`

Supported platforms: Android.

Type: [ReactNode](https://reactnative.dev/docs/react-node)

Slot-based children (use `.Icon` and `.Text` sub-components).

### `expanded`

Supported platforms: Android.

Optional • Type: `boolean` • Default: `true`

Controls whether the label is shown (expanded) or hidden (collapsed).

#### Inherited props

-   [FloatingActionButtonProps](https://docs.expo.dev/versions/latest/sdk/ui/jetpack-compose/floatingactionbutton.md#floatingactionbuttonprops)

### `FloatingActionButton`

Supported platforms: Android.

Type: React.[Element](https://www.typescriptlang.org/docs/handbook/jsx.html#function-component)<[FloatingActionButtonProps](https://docs.expo.dev/versions/latest/sdk/ui/jetpack-compose/floatingactionbutton.md#floatingactionbuttonprops)\>

Renders a Material Design 3 standard `FloatingActionButton`.

Wraps [`FloatingActionButton`](https://developer.android.com/reference/kotlin/androidx/compose/material3/package-summary#FloatingActionButton\(kotlin.Function0,androidx.compose.ui.Modifier,androidx.compose.ui.graphics.Shape,androidx.compose.ui.graphics.Color,androidx.compose.ui.graphics.Color,androidx.compose.material3.FloatingActionButtonElevation,androidx.compose.foundation.interaction.MutableInteractionSource,kotlin.Function0\)).

Example

```tsx
import { FloatingActionButton, Host, Icon } from '@expo/ui/jetpack-compose';

<Host matchContents>
  <FloatingActionButton onClick={() => console.log('pressed')}>
    <FloatingActionButton.Icon>
      <Icon source={require('./assets/add.xml')} />
    </FloatingActionButton.Icon>
  </FloatingActionButton>
</Host>
```

Props shared by all `FloatingActionButton` variants.

FloatingActionButtonProps

### `children`

Supported platforms: Android.

Type: [ReactNode](https://reactnative.dev/docs/react-node)

Slot-based children (use `.Icon` sub-component).

### `containerColor`

Supported platforms: Android.

Optional • Type: [ColorValue](https://reactnative.dev/docs/colors)

The background color of the button container. Defaults to `FloatingActionButtonDefaults.containerColor` (primary container).

### `modifiers`

Supported platforms: Android.

Optional • Type: `ModifierConfig[]`

Modifiers for the component.

### `onClick`

Supported platforms: Android.

Optional • Type: `() => void`

Callback invoked when the button is clicked.

### `LargeFloatingActionButton`

Supported platforms: Android.

Type: React.[Element](https://www.typescriptlang.org/docs/handbook/jsx.html#function-component)<[LargeFloatingActionButtonProps](https://docs.expo.dev/versions/latest/sdk/ui/jetpack-compose/floatingactionbutton.md#largefloatingactionbuttonprops)\>

Renders a Material Design 3 large `FloatingActionButton`.

Wraps [`LargeFloatingActionButton`](https://developer.android.com/reference/kotlin/androidx/compose/material3/package-summary#LargeFloatingActionButton\(kotlin.Function0,androidx.compose.ui.Modifier,androidx.compose.ui.graphics.Shape,androidx.compose.ui.graphics.Color,androidx.compose.ui.graphics.Color,androidx.compose.material3.FloatingActionButtonElevation,androidx.compose.foundation.interaction.MutableInteractionSource,kotlin.Function0\)).

Example

```tsx
import { LargeFloatingActionButton, Host, Icon } from '@expo/ui/jetpack-compose';

<Host matchContents>
  <LargeFloatingActionButton onClick={() => console.log('pressed')}>
    <LargeFloatingActionButton.Icon>
      <Icon source={require('./assets/add.xml')} />
    </LargeFloatingActionButton.Icon>
  </LargeFloatingActionButton>
</Host>
```

Props for the `LargeFloatingActionButton` component. Same as [`FloatingActionButtonProps`](https://docs.expo.dev/versions/latest/sdk/ui/jetpack-compose/floatingactionbutton.md#floatingactionbuttonprops).

LargeFloatingActionButtonProps

#### Inherited props

-   [FloatingActionButtonProps](https://docs.expo.dev/versions/latest/sdk/ui/jetpack-compose/floatingactionbutton.md#floatingactionbuttonprops)

### `SmallFloatingActionButton`

Supported platforms: Android.

Type: React.[Element](https://www.typescriptlang.org/docs/handbook/jsx.html#function-component)<[SmallFloatingActionButtonProps](https://docs.expo.dev/versions/latest/sdk/ui/jetpack-compose/floatingactionbutton.md#smallfloatingactionbuttonprops)\>

Renders a Material Design 3 small `FloatingActionButton`.

Wraps [`SmallFloatingActionButton`](https://developer.android.com/reference/kotlin/androidx/compose/material3/package-summary#SmallFloatingActionButton\(kotlin.Function0,androidx.compose.ui.Modifier,androidx.compose.ui.graphics.Shape,androidx.compose.ui.graphics.Color,androidx.compose.ui.graphics.Color,androidx.compose.material3.FloatingActionButtonElevation,androidx.compose.foundation.interaction.MutableInteractionSource,kotlin.Function0\)).

Example

```tsx
import { SmallFloatingActionButton, Host, Icon } from '@expo/ui/jetpack-compose';

<Host matchContents>
  <SmallFloatingActionButton onClick={() => console.log('pressed')}>
    <SmallFloatingActionButton.Icon>
      <Icon source={require('./assets/add.xml')} />
    </SmallFloatingActionButton.Icon>
  </SmallFloatingActionButton>
</Host>
```

Props for the `SmallFloatingActionButton` component. Same as [`FloatingActionButtonProps`](https://docs.expo.dev/versions/latest/sdk/ui/jetpack-compose/floatingactionbutton.md#floatingactionbuttonprops).

SmallFloatingActionButtonProps

#### Inherited props

-   [FloatingActionButtonProps](https://docs.expo.dev/versions/latest/sdk/ui/jetpack-compose/floatingactionbutton.md#floatingactionbuttonprops)
