Compose 修饰符列表

操作

作用域:任意
<T : Any?> Modifier.anchoredDraggable(
    state: AnchoredDraggableState<T>,
    orientation: Orientation,
    enabled: Boolean,
    interactionSource: MutableInteractionSource?,
    overscrollEffect: OverscrollEffect?,
    flingBehavior: FlingBehavior?
)

启用一组预定义值之间的拖动手势。

作用域:任意
<T : Any?> Modifier. anchoredDraggable(
    state: AnchoredDraggableState<T>,
    orientation: Orientation,
    enabled: Boolean,
    interactionSource: MutableInteractionSource?,
    overscrollEffect: OverscrollEffect?,
    startDragImmediately: Boolean,
    flingBehavior: FlingBehavior?
)

此函数已废弃。 startDragImmediately 已移除,且无替代项。

作用域:任意
<T : Any?> Modifier.anchoredDraggable(
    state: AnchoredDraggableState<T>,
    reverseDirection: Boolean,
    orientation: Orientation,
    enabled: Boolean,
    interactionSource: MutableInteractionSource?,
    overscrollEffect: OverscrollEffect?,
    flingBehavior: FlingBehavior?
)

启用一组预定义值之间的拖动手势。

作用域:任意
<T : Any?> Modifier. anchoredDraggable(
    state: AnchoredDraggableState<T>,
    reverseDirection: Boolean,
    orientation: Orientation,
    enabled: Boolean,
    interactionSource: MutableInteractionSource?,
    overscrollEffect: OverscrollEffect?,
    startDragImmediately: Boolean,
    flingBehavior: FlingBehavior?
)

此函数已废弃。 startDragImmediately 已移除,且无替代项。

作用域:任意
Modifier.clickable(
    enabled: Boolean,
    onClickLabel: String?,
    role: Role?,
    onClick: () -> Unit
)

将组件配置为通过输入或无障碍“点击”事件接收点击操作。

作用域:Any
Modifier.clickable(
    interactionSource: MutableInteractionSource?,
    indication: Indication?,
    enabled: Boolean,
    onClickLabel: String?,
    role: Role?,
    onClick: () -> Unit
)

将组件配置为通过输入或无障碍“点击”事件接收点击操作。

作用域:Any
Modifier.combinedClickable(
    enabled: Boolean,
    onClickLabel: String?,
    role: Role?,
    onLongClickLabel: String?,
    onLongClick: (() -> Unit)?,
    onDoubleClick: (() -> Unit)?,
    hapticFeedbackEnabled: Boolean,
    onClick: () -> Unit
)

将组件配置为通过输入或无障碍“点击”事件接收点击、双击和长按操作。

作用域:Any
Modifier.combinedClickable(
    interactionSource: MutableInteractionSource?,
    indication: Indication?,
    enabled: Boolean,
    onClickLabel: String?,
    role: Role?,
    onLongClickLabel: String?,
    onLongClick: (() -> Unit)?,
    onDoubleClick: (() -> Unit)?,
    hapticFeedbackEnabled: Boolean,
    onClick: () -> Unit
)

将组件配置为通过输入或无障碍“点击”事件接收点击、双击和长按操作。

作用域:任意
Modifier.draggable2D(
    state: Draggable2DState,
    enabled: Boolean,
    interactionSource: MutableInteractionSource?,
    startDragImmediately: Boolean,
    onDragStarted: (startedPosition: Offset) -> Unit,
    onDragStopped: (velocity: Velocity) -> Unit,
    reverseDirection: Boolean
)

为界面元素配置两个方向的触摸拖动操作。

作用域:任意
Modifier.draggable(
    state: DraggableState,
    orientation: Orientation,
    enabled: Boolean,
    interactionSource: MutableInteractionSource?,
    startDragImmediately: Boolean,
    onDragStarted: suspend CoroutineScope.(startedPosition: Offset) -> Unit,
    onDragStopped: suspend CoroutineScope.(velocity: Float) -> Unit,
    reverseDirection: Boolean
)

为界面元素配置单个 Orientation 的触摸拖动。

作用域:Any

使用此修饰符将用于实现无障碍功能的一系列 selectable 项(例如 Tab 或 RadioButton)归到一组。

作用域:Any
Modifier.selectable(
    selected: Boolean,
    enabled: Boolean,
    role: Role?,
    onClick: () -> Unit
)

将组件配置为可选择,通常作为互斥组的一部分,在任何时间点只能选择该组中的一项。

作用域:Any
Modifier.selectable(
    selected: Boolean,
    interactionSource: MutableInteractionSource?,
    indication: Indication?,
    enabled: Boolean,
    role: Role?,
    onClick: () -> Unit
)

将组件配置为可选择,通常作为互斥组的一部分,在任何时间点只能选择该组中的一项。

作用域:任意
@ExperimentalMaterialApi
<T : Any?> Modifier. swipeable(
    state: SwipeableState<T>,
    anchors: Map<Float, T>,
    orientation: Orientation,
    enabled: Boolean,
    reverseDirection: Boolean,
    interactionSource: MutableInteractionSource?,
    thresholds: (from, to) -> ThresholdConfig,
    resistance: ResistanceConfig?,
    velocityThreshold: Dp
)

此函数已废弃。Material 的可滑动浏览已被 Foundation 的 AnchoredDraggable API 取代。

作用域:任意
@ExperimentalWearMaterialApi
<T : Any?> Modifier.swipeable(
    state: SwipeableState<T>,
    anchors: Map<Float, T>,
    orientation: Orientation,
    enabled: Boolean,
    reverseDirection: Boolean,
    interactionSource: MutableInteractionSource?,
    thresholds: (from, to) -> ThresholdConfig,
    resistance: ResistanceConfig?,
    velocityThreshold: Dp
)

在一组预定义状态之间启用滑动手势。

作用域:Any
Modifier.toggleable(
    value: Boolean,
    enabled: Boolean,
    role: Role?,
    onValueChange: (Boolean) -> Unit
)

将组件配置为可通过输入和无障碍事件切换

作用域:Any
Modifier.toggleable(
    value: Boolean,
    interactionSource: MutableInteractionSource?,
    indication: Indication?,
    enabled: Boolean,
    role: Role?,
    onValueChange: (Boolean) -> Unit
)

将组件配置为可通过输入和无障碍事件切换。

作用域:Any
Modifier.triStateToggleable(
    state: ToggleableState,
    enabled: Boolean,
    role: Role?,
    onClick: () -> Unit
)

将组件配置为可通过输入和无障碍事件在三种状态之间切换:启用、停用和不确定。

作用域:Any
Modifier.triStateToggleable(
    state: ToggleableState,
    interactionSource: MutableInteractionSource?,
    indication: Indication?,
    enabled: Boolean,
    role: Role?,
    onClick: () -> Unit
)

将组件配置为可通过输入和无障碍事件在三种状态之间切换:启用、停用和不确定。

作用域: PaneScaffoldScope
@ExperimentalMaterial3AdaptiveApi
Modifier.paneExpansionDraggable(
    state: PaneExpansionState,
    minTouchTargetSize: Dp,
    interactionSource: MutableInteractionSource
)

应该应用于拖动手柄可组合项的修饰符,以便正确拖动拖动手柄并在提供的 PaneExpansionState 上执行操作。

对齐方式

作用域: RowScope

Row 中垂直对齐元素。

作用域: RowScope
Modifier.alignBy(alignmentLineBlock: (Measured) -> Int)

垂直放置元素,使由 alignmentLineBlock 确定的内容的对齐线与同样配置为 alignBy 的同级元素对齐。

作用域: RowScope

垂直放置元素,使其 alignmentLine 与同样配置为 alignBy 的同级元素对齐。

作用域: RowScope

垂直放置元素,使其第一条基线与同样配置为 alignByBaselinealignBy 的同级元素对齐。

作用域: ColumnScope

Column 中水平对齐元素。

作用域: ColumnScope
Modifier.alignBy(alignmentLineBlock: (Measured) -> Int)

水平放置元素,使由 alignmentLineBlock 确定的内容的对齐线与同样配置为 alignBy 的同级元素对齐。

作用域: ColumnScope

水平放置元素,使其 alignmentLine 与同样配置为 alignBy 的同级元素对齐。

作用域: BoxScope
Modifier.align(alignment: Alignment)

将内容元素拉取到 Box 中的特定 Alignment

动画

作用域:任意
@ExperimentalSharedTransitionApi
Modifier.animateBounds(
    lookaheadScope: LookaheadScope,
    modifier: Modifier,
    boundsTransform: BoundsTransform,
    animateMotionFrameOfReference: Boolean
)

Modifier,用于为 LookaheadScope 内发生的布局更改(位置和/或大小)添加动画效果。

作用域:任意
@ExperimentalMaterial3ExpressiveApi
Modifier.animateFloatingActionButton(
    visible: Boolean,
    alignment: Alignment,
    targetScale: Float,
    scaleAnimationSpec: AnimationSpec<Float>?,
    alphaAnimationSpec: AnimationSpec<Float>?
)

将此修饰符应用于 FloatingActionButton,以使用动画(通常基于应用的主要内容滚动操作)显示或隐藏它。

open
Modifier.animateEnterExit(
    enter: EnterTransition,
    exit: ExitTransition,
    label: String
)

animateEnterExit 修饰符可用于 AnimatedVisibility 的任何直接或间接子项,以创建与 AnimatedVisibility 中指定的内容不同的进入/退出动画。

作用域: LazyItemScope
open
Modifier.animateItem(
    fadeInSpec: FiniteAnimationSpec<Float>?,
    placementSpec: FiniteAnimationSpec<IntOffset>?,
    fadeOutSpec: FiniteAnimationSpec<Float>?
)

此修饰符可为项的外观(淡入)、消失(淡出)和位置变化(例如项重新排序)添加动画效果。

作用域: LazyGridItemScope
Modifier.animateItem(
    fadeInSpec: FiniteAnimationSpec<Float>?,
    placementSpec: FiniteAnimationSpec<IntOffset>?,
    fadeOutSpec: FiniteAnimationSpec<Float>?
)

此修饰符可为项的外观(淡入)、消失(淡出)和位置变化(例如项重新排序)添加动画效果。

Modifier.animateItem(
    fadeInSpec: FiniteAnimationSpec<Float>?,
    placementSpec: FiniteAnimationSpec<IntOffset>?,
    fadeOutSpec: FiniteAnimationSpec<Float>?
)

此修饰符可为项的外观(淡入)、消失(淡出)和位置变化(例如项重新排序)添加动画效果。

边框

作用域:Any
Modifier.border(border: BorderStroke, shape: Shape)

修改元素,以添加使用 bordershape 指定了外观的边框,并进行裁剪。

作用域:Any
Modifier.border(width: Dp, brush: Brush, shape: Shape)

修改元素,以添加使用 widthbrushshape 指定了外观的边框,并进行裁剪。

作用域:Any
Modifier.border(width: Dp, color: Color, shape: Shape)

修改元素,以添加使用 widthcolorshape 指定了外观的边框,并进行裁剪。

绘图

作用域:Any
Modifier.alpha(alpha: Float)

使用可能小于 1 的修饰的 alpha 绘制内容。

作用域:Any
Modifier.background(color: Color, shape: Shape)

使用纯 color 在内容后方绘制 shape

作用域:Any
Modifier.background(
    brush: Brush,
    shape: Shape,
    alpha: @FloatRange(from = 0.0, to = 1.0) Float
)

使用 brush 在内容后方绘制 shape

作用域:Any
Modifier.clip(shape: Shape)

将内容裁剪到 shape

作用域:Any

将内容裁剪到此修饰符定义的图层的边界。

作用域:Any
Modifier.drawBehind(onDraw: DrawScope.() -> Unit)

绘制到修饰的内容后方的 Canvas 中。

作用域:Any
Modifier.drawWithCache(onBuildDrawCache: CacheDrawScope.() -> DrawResult)

绘制到 DrawScope 中,只要绘制区域的大小不变或读取的任何状态对象未发生变化,便使内容在各绘制调用中始终保留。

作用域:Any

创建 DrawModifier,允许开发者在布局内容前后进行绘制。

作用域:Any
Modifier.indication(
    interactionSource: InteractionSource,
    indication: Indication?
)

在发生互动时为此组件绘制视觉效果。

作用域:Any
Modifier.paint(
    painter: Painter,
    sizeToIntrinsics: Boolean,
    alignment: Alignment,
    contentScale: ContentScale,
    alpha: Float,
    colorFilter: ColorFilter?
)

使用 painter 绘制内容。

作用域:Any
Modifier.shadow(
    elevation: Dp,
    shape: Shape,
    clip: Boolean,
    ambientColor: Color,
    spotColor: Color
)

创建一个用于绘制阴影的 graphicsLayer

作用域:Any

添加内边距,以适应 safe drawing 边衬区。

作用域:Any
Modifier.zIndex(zIndex: Float)

创建一个修饰符,用于控制同一布局父项的子项的绘制顺序。

焦点

作用域:Any
Modifier.onFocusChanged(onFocusChanged: (FocusState) -> Unit)

将此修饰符添加到组件,以观察焦点状态事件。

作用域:Any
Modifier.onFocusEvent(onFocusEvent: (FocusState) -> Unit)

将此修饰符添加到组件,以观察焦点状态事件。

作用域:Any

此函数已废弃。取而代之的是 focusTarget

作用域:Any

将此修饰符添加到组件,以使其可聚焦。

作用域:Any
Modifier. focusOrder(focusOrderReceiver: FocusOrder.() -> Unit)

此函数已废弃。请改用 focusProperties()

作用域:Any
Modifier. focusOrder(focusRequester: FocusRequester)

此函数已废弃。请改用 focusRequester()

作用域:Any
Modifier. focusOrder(
    focusRequester: FocusRequester,
    focusOrderReceiver: FocusOrder.() -> Unit
)

此函数已废弃。请改用 focusProperties() 和 focusRequester()

作用域:Any

此修饰符可让您指定可供修饰符链中更底层或子布局节点上的 focusTarget 访问的属性。

作用域:Any

将此修饰符添加到组件中,以请求更改焦点。

作用域:任意

此修饰符可用于保存焦点并将其恢复至焦点小组。

作用域:任意

此函数已废弃。请改用 focusRestorer(FocusRequester)

作用域:任意

创建焦点群组或将此组件标记为焦点群组。

作用域:Any
Modifier.focusable(
    enabled: Boolean,
    interactionSource: MutableInteractionSource?
)

将组件配置为可通过焦点系统或无障碍“焦点”事件聚焦。

作用域:Any
Modifier.onFocusedBoundsChanged(
    onPositioned: (LayoutCoordinates?) -> Unit
)

每当当前聚焦区域的边界发生变化时,就会调用 onPositioned

Graphics

作用域:Any

Modifier.Node 可使内容绘制到绘图层。

作用域:Any
Modifier.graphicsLayer(
    scaleX: Float,
    scaleY: Float,
    alpha: Float,
    translationX: Float,
    translationY: Float,
    shadowElevation: Float,
    rotationX: Float,
    rotationY: Float,
    rotationZ: Float,
    cameraDistance: Float,
    transformOrigin: TransformOrigin,
    shape: Shape,
    clip: Boolean,
    renderEffect: RenderEffect?,
    ambientShadowColor: Color,
    spotShadowColor: Color,
    compositingStrategy: CompositingStrategy
)

Modifier.Element 可使内容绘制到绘图层。

作用域:Any

Modifier.Element 可添加绘制图层,以便工具可以识别所绘制图片中的元素。

键盘

作用域:Any
Modifier.onKeyEvent(onKeyEvent: (KeyEvent) -> Boolean)

将此 modifier 添加到组件的 modifier 参数中后,它可以在自身(或其子项之一)获得焦点时拦截硬件按键事件。

作用域:Any
Modifier.onPreviewKeyEvent(onPreviewKeyEvent: (KeyEvent) -> Boolean)

将此 modifier 添加到组件的 modifier 参数中后,它可以在自身(或其子项之一)获得焦点时拦截硬件按键事件。

Layout

作用域:任意
Modifier.layoutId(layoutId: String, tag: String?)

支持使用 tagandroidx.compose.ui.layout.layoutId 的替代方法。

作用域:任意
Modifier.layoutId(layoutId: Any)

使用 layoutId 标记元素,以在其父项中识别它。

作用域:Any

创建 LayoutModifier,以允许更改已封装元素的测量和布局方式。

作用域:Any
Modifier.onGloballyPositioned(
    onGloballyPositioned: (LayoutCoordinates) -> Unit
)

当内容的全局位置可能发生变化时,使用元素的 LayoutCoordinates 调用 onGloballyPositioned

内边距

作用域:Any
Modifier.paddingFrom(alignmentLine: AlignmentLine, before: Dp, after: Dp)

Modifier 可添加内边距,以根据从内容边界到 alignment line 的指定距离放置内容。

作用域:Any
Modifier.paddingFrom(
    alignmentLine: AlignmentLine,
    before: TextUnit,
    after: TextUnit
)

Modifier 可添加内边距,以根据从内容边界到 alignment line 的指定距离放置内容。

作用域:Any
Modifier.paddingFromBaseline(top: Dp, bottom: Dp)

Modifier 用于在布局中放置内容,使从布局顶部到 baseline of the first line of text in the content 的距离为 top,且从 baseline of the last line of text in the content 到布局底部的距离为 bottom

作用域:Any

Modifier 用于在布局中放置内容,使从布局顶部到 baseline of the first line of text in the content 的距离为 top,且从 baseline of the last line of text in the content 到布局底部的距离为 bottom

作用域:Any
Modifier.absolutePadding(left: Dp, top: Dp, right: Dp, bottom: Dp)

沿着内容的每个边缘应用 Dp 的额外空间:lefttoprightbottom

作用域:任意

沿着内容的每个边缘(左侧、顶部、右侧和底部)应用 all dp 的额外空间。

作用域:Any
Modifier.padding(paddingValues: PaddingValues)

向组件应用 PaddingValues,将其作为沿内容左侧、顶部、右侧和底部的额外空间。

作用域:任意
Modifier.padding(horizontal: Dp, vertical: Dp)

沿着内容的左侧和右侧边缘应用 horizontal dp 空间,并沿着顶部和底部边缘应用 vertical dp 空间。

作用域:任意
Modifier.padding(start: Dp, top: Dp, end: Dp, bottom: Dp)

沿着内容的每个边缘应用 Dp 的额外空间:starttopendbottom

作用域:任意

添加内边距,以适应 caption bar 边衬区。

作用域:Any

添加内边距,以适应 display cutout

作用域:Any

添加内边距,以适应 ime 边衬区。

作用域:Any

添加内边距,以适应 mandatory system gestures 边衬区。

作用域:Any

添加内边距,以适应 navigation bars 边衬区。

作用域:Any

添加内边距,以适应 safe content 边衬区。

作用域:Any

添加内边距,以适应 safe gestures 边衬区。

作用域:Any

添加内边距,以适应 status bars 边衬区。

作用域:Any

添加内边距,以适应 system bars 边衬区。

作用域:Any

添加内边距,以适应 system gestures 边衬区。

作用域:Any

添加内边距,以适应 waterfall 边衬区。

作用域:Any

添加内边距,使内容不会进入 insets 空间。

Pointer

作用域:任意
Modifier.pointerHoverIcon(
    icon: PointerIcon,
    overrideDescendants: Boolean
)

可让开发者定义光标悬停在元素上时要显示的指针图标的修饰符。

作用域:任意
Modifier.pointerInteropFilter(
    requestDisallowInterceptTouchEvent: RequestDisallowInterceptTouchEvent?,
    onTouchEvent: (MotionEvent) -> Boolean
)

一个特殊的 PointerInputModifier,可提供对最初分派到 Compose 的底层 MotionEvent 的访问权限。

作用域:Any
Modifier. pointerInput(block: suspend PointerInputScope.() -> Unit)

此函数已废弃。Modifier.pointerInput 必须提供一个或多个“key”参数来定义此修饰符的身份,以及确定应在何时取消它的上一个输入处理协程并为新键启动新效果。

作用域:Any

创建一个用于在修饰的元素区域内处理指针输入的修饰符。

作用域:Any
Modifier.pointerInput(vararg keys: Any?, block: PointerInputEventHandler)

创建一个用于在修饰的元素区域内处理指针输入的修饰符。

作用域:Any
Modifier.pointerInput(
    key1: Any?,
    key2: Any?,
    block: PointerInputEventHandler
)

创建一个用于在修饰的元素区域内处理指针输入的修饰符。

位置

作用域:任意

将内容偏移 offset 像素。

作用域:Any

将内容偏移(x dp,y dp)。

作用域:Any
Modifier.offset(offset: Density.() -> IntOffset)

将内容偏移 offset 像素。

作用域:Any
Modifier.offset(x: Dp, y: Dp)

将内容偏移(x dp,y dp)。

作用域: TabRowDefaults
Modifier.tabIndicatorOffset(currentTabPosition: TabPosition)

Modifier 会占用 TabRow 内的所有可用宽度,然后以动画方式呈现它应用到指示器的偏移量(具体取决于 currentTabPosition)。

作用域: TabRowDefaults
Modifier.tabIndicatorOffset(currentTabPosition: TabPosition)

Modifier 会占用 TabRow 内的所有可用宽度,然后以动画方式呈现它应用到指示器的偏移量(具体取决于 currentTabPosition)。

语义

作用域:任意

包含不确定性进度指示器所需的 semantics,它表示操作正在进行中。

作用域:任意
Modifier.progressSemantics(
    value: Float,
    valueRange: ClosedFloatingPointRange<Float>,
    steps: @IntRange(from = 0) Int
)

包含确定性进度指示器或滑块的进度部分所需的 semantics,它表示 valueRange 内的进度。

作用域:任意
Modifier.rangeSemantics(
    value: Float,
    enabled: Boolean,
    onValueChange: (Float) -> Unit,
    valueRange: ClosedFloatingPointRange<Float>,
    steps: Int
)

用于添加表示步进器/滑块进度的语义的修饰符。

作用域:任意

清除所有后代节点的语义并设置新语义。

作用域:Any
Modifier.semantics(mergeDescendants: Boolean, properties: SemanticsPropertyReceiver.() -> Unit)

将语义键值对添加到布局节点,以便用于测试、无障碍功能等。

滚动

作用域:Any

裁剪可滚动容器在主轴上的边界,同时在交叉轴上为背景效果(例如阴影)留出空间。

作用域:Any
Modifier.nestedScroll(
    connection: NestedScrollConnection,
    dispatcher: NestedScrollDispatcher?
)

修改元素,以使其参与嵌套滚动层次结构。

作用域:任意
Modifier.overscroll(overscrollEffect: OverscrollEffect?)

通过提供的 overscrollEffect 渲染滚动回弹。

作用域:任意
Modifier.onPreRotaryScrollEvent(
    onPreRotaryScrollEvent: (RotaryScrollEvent) -> Boolean
)

将此 modifier 添加到组件的 modifier 参数中后,它可以在自身(或其子项之一)获得焦点时拦截 RotaryScrollEvent

作用域:Any
Modifier.onRotaryScrollEvent(
    onRotaryScrollEvent: (RotaryScrollEvent) -> Boolean
)

将此 modifier 添加到组件的 modifier 参数中后,它可以在自身(或其子项之一)获得焦点时拦截 RotaryScrollEvent

作用域:任意
Modifier.rotaryScrollable(
    behavior: RotaryScrollableBehavior,
    focusRequester: FocusRequester,
    reverseDirection: Boolean
)

一个修饰符,用于将旋转事件与可滚动容器(如 Column、LazyList 等)连接起来。

作用域:任意
Modifier.scrollAway(
    scrollInfoProvider: ScrollInfoProvider,
    screenStage: () -> ScreenStage
)

根据滚动列表提供的滚动状态,垂直滚动进入/离开视图。

作用域:任意
Modifier.scrollAway(scrollState: ScrollState, offset: Dp)

根据 ScrollState 使项目垂直滚入/滚出视图。

作用域:Any
Modifier.scrollAway(
    scrollState: LazyListState,
    itemIndex: Int,
    offset: Dp
)

根据 LazyListState 使项目垂直滚入/滚出视图。

作用域:Any
Modifier.scrollAway(
    scrollState: ScalingLazyListState,
    itemIndex: Int,
    offset: Dp
)

根据 ScalingLazyListState 使项目垂直滚入/滚出视图。

作用域:任意
Modifier. scrollAway(
    scrollState: ScalingLazyListState,
    itemIndex: Int,
    offset: Dp
)

此函数已废弃。提供此重载是为了向后兼容 Compose for Wear OS 1.1。现在有一个较新的重载,它使用 wear.compose.foundation.lazy 软件包中的 ScalingLazyListState

作用域:任意
Modifier.horizontalScroll(
    state: ScrollState,
    enabled: Boolean,
    flingBehavior: FlingBehavior?,
    reverseScrolling: Boolean
)

修改元素,以支持在内容的宽度大于允许的最大约束时水平滚动。

作用域:任意
Modifier.horizontalScroll(
    state: ScrollState,
    overscrollEffect: OverscrollEffect?,
    enabled: Boolean,
    flingBehavior: FlingBehavior?,
    reverseScrolling: Boolean
)

修改元素,以支持在内容的宽度大于允许的最大约束时水平滚动。

作用域:Any
Modifier.verticalScroll(
    state: ScrollState,
    enabled: Boolean,
    flingBehavior: FlingBehavior?,
    reverseScrolling: Boolean
)

修改元素,以支持在内容的高度大于允许的最大约束值时垂直滚动。

作用域:任意
Modifier.verticalScroll(
    state: ScrollState,
    overscrollEffect: OverscrollEffect?,
    enabled: Boolean,
    flingBehavior: FlingBehavior?,
    reverseScrolling: Boolean
)

修改元素,以支持在内容的高度大于允许的最大约束值时垂直滚动。

作用域:任意

一个修饰符,用于为 TransformingLazyColumn 项中的内容启用 Material3 Motion 转换功能。

作用域:任意
@Composable
Modifier.scrollTransform(
    scope: TransformingLazyColumnItemScope,
    backgroundColor: Color,
    shape: Shape
)

一个修饰符,用于为 TransformingLazyColumn 项中的内容启用 Material3 Motion 转换功能。

作用域:任意
@Composable
Modifier.scrollTransform(
    scope: TransformingLazyColumnItemScope,
    shape: Shape,
    painter: Painter,
    border: BorderStroke?
)

一个修饰符,用于为 TransformingLazyColumn 项中的内容启用 Material3 Motion 转换功能。

作用域:任意
Modifier.scrollable(
    state: ScrollableState,
    orientation: Orientation,
    enabled: Boolean,
    reverseDirection: Boolean,
    flingBehavior: FlingBehavior?,
    interactionSource: MutableInteractionSource?
)

在单个 Orientation 为界面元素配置触摸滚动和快速滑动。

作用域:Any
Modifier.scrollable(
    state: ScrollableState,
    orientation: Orientation,
    overscrollEffect: OverscrollEffect?,
    enabled: Boolean,
    reverseDirection: Boolean,
    flingBehavior: FlingBehavior?,
    interactionSource: MutableInteractionSource?,
    bringIntoViewSpec: BringIntoViewSpec?
)

在单个 Orientation 为界面元素配置触摸滚动和快速滑动。

作用域:Any

在 Android R 及更高版本上将软键盘控制为嵌套滚动。

大小

作用域:Any
Modifier.animateContentSize(
    animationSpec: FiniteAnimationSpec<IntSize>,
    finishedListener: ((initialValue: IntSize, targetValue: IntSize) -> Unit)?
)

此修饰符会在其子修饰符(或子可组合项,如果它已位于链尾)更改尺寸时为其自己的尺寸添加动画效果。

作用域:任意
Modifier.animateContentSize(
    animationSpec: FiniteAnimationSpec<IntSize>,
    alignment: Alignment,
    finishedListener: ((initialValue: IntSize, targetValue: IntSize) -> Unit)?
)

此修饰符会在其子修饰符(或子可组合项,如果它已位于链尾)更改尺寸时为其自己的尺寸添加动画效果。

作用域:Any
Modifier.aspectRatio(
    ratio: @FloatRange(from = 0.0, fromInclusive = false) Float,
    matchHeightConstraintsFirst: Boolean
)

尝试按以下顺序匹配传入的约束条件之一,以调整内容大小以匹配指定的宽高比:如果 matchHeightConstraintsFirstfalse(默认值),则为 Constraints.maxWidthConstraints.maxHeightConstraints.minWidthConstraints.minHeight;如果 matchHeightConstraintsFirsttrue,则为 Constraints.maxHeightConstraints.maxWidthConstraints.minHeightConstraints.minWidth

作用域:任意

保留至少 48.dp 的尺寸,以便在元素尺寸较小时消除触摸交互的歧义。

作用域:任意

保留至少 48.dp 的尺寸,以便在元素尺寸较小时消除触摸交互的歧义。

作用域:任意

保留至少 48.dp 的尺寸,以便在元素尺寸较小时消除触摸交互的歧义。

作用域:任意

保留至少 48.dp 的尺寸,以便在元素尺寸较小时消除触摸交互的歧义。

作用域:任意
Modifier.height(intrinsicSize: IntrinsicSize)

将内容的首选高度声明为与内容的最小或最大固有高度相同。

作用域:Any

将内容的高度声明为与内容的最小或最大固有高度完全相同。

作用域:Any

将内容的宽度声明为与内容的最小或最大固有宽度完全相同。

作用域:Any
Modifier.width(intrinsicSize: IntrinsicSize)

将内容的首选宽度声明为与内容的最小或最大固有宽度相同。

作用域:Any
Modifier.onSizeChanged(onSizeChanged: (IntSize) -> Unit)

首次测量元素时或元素的大小发生变化时,通过修改后的 Compose 界面元素的大小进行调用。

作用域:Any
Modifier.defaultMinSize(minWidth: Dp, minHeight: Dp)

仅在封装的布局不受约束时约束其尺寸:minWidthminHeight 约束仅在传入的相应约束为 0 时应用。

作用域:Any
Modifier.fillMaxHeight(fraction: @FloatRange(from = 0.0, to = 1.0) Float)

让内容填充(可能仅部分填充)传入的测量约束的 Constraints.maxHeight,方法是将 minimum heightmaximum height 设置为等于 maximum height 乘以 fraction 得出的值。

作用域:Any
Modifier.fillMaxSize(fraction: @FloatRange(from = 0.0, to = 1.0) Float)

通过将 minimum widthmaximum width 设置为等于 maximum width 乘以 fraction,以及将 minimum heightmaximum height 设置为等于 maximum height 乘以 fraction,让内容填充(可能仅部分填充)传入测量约束的 Constraints.maxWidthConstraints.maxHeight

作用域:Any
Modifier.fillMaxWidth(fraction: @FloatRange(from = 0.0, to = 1.0) Float)

让内容填充(可能仅部分填充)传入的测量约束的 Constraints.maxWidth,方法是将 minimum widthmaximum width 设置为等于 maximum width 乘以 fraction 得出的值。

作用域:Any
Modifier.height(height: Dp)

将内容的首选高度声明为正好 heightdp。

作用域:Any
Modifier.heightIn(min: Dp, max: Dp)

如果传入的测量 Constraints 允许,将内容的高度限制在 mindp 与 maxdp 之间。

作用域:Any

将内容的高度声明为正好 heightdp。

作用域:Any
Modifier.requiredHeightIn(min: Dp, max: Dp)

将内容的高度限制在 mindp 与 maxdp 之间。

作用域:Any

将内容的尺寸声明为宽度和高度正好是 sizedp。

作用域:任意

将内容的尺寸声明为正好 size

作用域:任意
Modifier.requiredSize(width: Dp, height: Dp)

将内容的尺寸声明为正好是 widthdp 和 heightdp。

作用域:任意
Modifier.requiredSizeIn(
    minWidth: Dp,
    minHeight: Dp,
    maxWidth: Dp,
    maxHeight: Dp
)

将内容的宽度限制在 minWidthdp 与 maxWidthdp 之间,并将内容的高度限制在 minHeightdp 与 maxHeightdp 之间。

作用域:Any

将内容的宽度声明为正好 widthdp。

作用域:Any
Modifier.requiredWidthIn(min: Dp, max: Dp)

将内容的宽度限制在 mindp 与 maxdp 之间。

作用域:Any
Modifier.size(size: Dp)

将内容的首选尺寸声明为正好是 sizedp 的方形。

作用域:任意
Modifier.size(size: DpSize)

将内容的首选尺寸声明为正好 size

作用域:任意
Modifier.size(width: Dp, height: Dp)

将内容的首选尺寸声明为正好是 widthdp x heightdp。

作用域:任意
Modifier.sizeIn(minWidth: Dp, minHeight: Dp, maxWidth: Dp, maxHeight: Dp)

如果传入的测量 Constraints 允许,将内容的宽度限制在 minWidthdp 与 maxWidthdp 之间,并将内容的高度限制在 minHeightdp 与 maxHeightdp 之间。

作用域:Any
Modifier.width(width: Dp)

将内容的首选宽度声明为正好 widthdp。

作用域:Any
Modifier.widthIn(min: Dp, max: Dp)

如果传入的测量 Constraints 允许,将内容的宽度限制在 mindp 与 maxdp 之间。

作用域:Any
Modifier.wrapContentHeight(
    align: Alignment.Vertical,
    unbounded: Boolean
)

允许在不考虑传入的测量 minimum height constraint 的情况下将内容测量为所需高度;如果 unbounded 为 true,则也可不考虑传入的测量 maximum height constraint

作用域:Any
Modifier.wrapContentSize(align: Alignment, unbounded: Boolean)

允许在不考虑传入的测量 minimum widthminimum height 约束的情况下将内容测量为所需大小;如果 unbounded 为 true,则也可不考虑传入的最大约束。

作用域:Any
Modifier.wrapContentWidth(
    align: Alignment.Horizontal,
    unbounded: Boolean
)

允许在不考虑传入的测量 minimum width constraint 的情况下以所需宽度测量内容;如果 unbounded 为 true,则也可不考虑传入的测量 maximum width constraint

作用域:任意

此修饰符在变形过渡期间为 scrollTransform 提供目标可组合项的高度,并表示变形时项的最小高度。

作用域:任意

用于同时为 IconButton 和 TextButton 设置大小和建议的触摸目标的修饰符。

作用域:任意

将高度设置为屏幕 bottominsets 的高度。

作用域:Any

根据 LayoutDirection,使用 leftright 将宽度设置为屏幕 endinsets 的宽度。

作用域:Any

根据 LayoutDirection,使用 leftright 将宽度设置为屏幕 startinsets 的宽度。

作用域:Any

将高度设置为屏幕 topinsets 的高度。

作用域: RowScope
Modifier.weight(
    weight: @FloatRange(from = 0.0, fromInclusive = false) Float,
    fill: Boolean
)

根据元素相对于 Row 中其他加权同级元素的 weight,按比例调整元素的宽度。

作用域: ColumnScope
Modifier.weight(
    weight: @FloatRange(from = 0.0, fromInclusive = false) Float,
    fill: Boolean
)

根据元素相对于 Column 中其他加权同级元素的 weight,按比例调整元素的高度。

作用域: FlowRowScope
@ExperimentalLayoutApi
Modifier.fillMaxRowHeight(fraction: @FloatRange(from = 0.0, to = 1.0) Float)

让项填充(可能仅部分填充)FlowRow 中其所在行中的最高项的最大高度。

作用域: FlowColumnScope
@ExperimentalLayoutApi
Modifier.fillMaxColumnWidth(
    fraction: @FloatRange(from = 0.0, to = 1.0) Float
)

让项填充(可能仅部分)填充其所在列中最宽的项的最大宽度(在 FlowColumn 内)。

作用域: BoxScope

在测量完所有其他内容元素后,调整元素的尺寸,使其与 Box 的尺寸一致。

作用域: LazyItemScope
Modifier.fillParentMaxHeight(
    fraction: @FloatRange(from = 0.0, to = 1.0) Float
)

让内容填充传入的测量约束的 Constraints.maxHeight,方法是将 minimum height 设置为等于 maximum height 乘以 fraction 得出的值。

作用域: LazyItemScope
Modifier.fillParentMaxSize(
    fraction: @FloatRange(from = 0.0, to = 1.0) Float
)

让内容填充父级测量约束的 Constraints.maxWidthConstraints.maxHeight,方法是将 minimum width 设置为等于 maximum width 乘以 fraction 得出的值,并将 minimum height 设置为等于 maximum height 乘以 fraction 得出的值。

作用域: LazyItemScope
Modifier.fillParentMaxWidth(
    fraction: @FloatRange(from = 0.0, to = 1.0) Float
)

让内容填充父级测量约束的 Constraints.maxWidth,方法是将 minimum width 设置为等于 maximum width 乘以 fraction 得出的值。

abstract
Modifier.exposedDropdownSize(matchTextFieldWidth: Boolean)

应应用于放置在作用域内的 ExposedDropdownMenu 的修饰符。

abstract
Modifier.exposedDropdownSize(matchAnchorWidth: Boolean)

应应用于放置在 ExposedDropdownMenuBoxScope 内的菜单的修饰符。

作用域: PaneScaffoldScope

此修饰符会指定窗格的首选宽度,当关联的窗格渲染为固定窗格(即不会拉伸以填充剩余空间)时,窗格 Scaffold 实现会尽可能遵循此宽度。

测试

作用域:Any

应用标记以允许在测试中找到修饰的元素。

变换

作用域:Any
Modifier.rotate(degrees: Float)

设置视图围绕可组合项中心旋转的角度。

作用域:任意
Modifier.scale(scale: Float)

按相同的缩放比例沿水平轴和垂直轴均匀缩放内容。

作用域:任意
Modifier.scale(scaleX: Float, scaleY: Float)

分别按以下缩放比例沿水平轴和垂直轴缩放可组合项的内容。

作用域:任意
Modifier.transformable(
    state: TransformableState,
    lockRotationOnZoomPan: Boolean,
    enabled: Boolean
)

启用修饰的界面元素的变换手势。

作用域:任意
Modifier.transformable(
    state: TransformableState,
    canPan: (Offset) -> Boolean,
    lockRotationOnZoomPan: Boolean,
    enabled: Boolean
)

启用修饰的界面元素的变换手势。

其他

作用域:任意

此函数已废弃。已由重载替换为用于获取传输数据的回调,启动检测由 Compose 自行执行

作用域:任意
Modifier.basicMarquee(
    iterations: Int,
    animationMode: MarqueeAnimationMode,
    repeatDelayMillis: Int,
    initialDelayMillis: Int,
    spacing: MarqueeSpacing,
    velocity: Dp
)

当修改过的内容因太宽而无法适应可用空间时,为修改后的内容应用动画选取框效果。

作用域:任意
Modifier.edgeSwipeToDismiss(
    swipeToDismissBoxState: SwipeToDismissBoxState,
    edgeWidth: Dp
)

将滑动关闭操作限制为只能从视口边缘开始操作。

作用域:任意
Modifier.blur(radius: Dp, edgeTreatment: BlurredEdgeTreatment)

绘制内容,并使用指定的半径模糊处理内容。

作用域:Any
Modifier.blur(
    radiusX: Dp,
    radiusY: Dp,
    edgeTreatment: BlurredEdgeTreatment
)

绘制内容,并使用指定的半径模糊处理内容。

作用域:任意
Modifier.bringIntoViewRequester(
    bringIntoViewRequester: BringIntoViewRequester
)

可用于发送 bringIntoView 请求的修饰符。

作用域:任意

此函数已废弃。改用 BringIntoViewModifierNode

作用域:任意
Modifier.composed(
    inspectorInfo: InspectorInfo.() -> Unit,
    factory: @Composable Modifier.() -> Modifier
)

声明将针对所修饰的每个元素进行组合的 Modifier 的即时组合。

作用域:Any
Modifier.composed(
    fullyQualifiedName: String,
    key1: Any?,
    inspectorInfo: InspectorInfo.() -> Unit,
    factory: @Composable Modifier.() -> Modifier
)

声明将针对所修饰的每个元素进行组合的 Modifier 的即时组合。

作用域:Any
Modifier.composed(
    fullyQualifiedName: String,
    vararg keys: Any?,
    inspectorInfo: InspectorInfo.() -> Unit,
    factory: @Composable Modifier.() -> Modifier
)

声明将针对所修饰的每个元素进行组合的 Modifier 的即时组合。

作用域:Any
Modifier.composed(
    fullyQualifiedName: String,
    key1: Any?,
    key2: Any?,
    inspectorInfo: InspectorInfo.() -> Unit,
    factory: @Composable Modifier.() -> Modifier
)

声明将针对所修饰的每个元素进行组合的 Modifier 的即时组合。

作用域:Any
Modifier.composed(
    fullyQualifiedName: String,
    key1: Any?,
    key2: Any?,
    key3: Any?,
    inspectorInfo: InspectorInfo.() -> Unit,
    factory: @Composable Modifier.() -> Modifier
)

声明将针对所修饰的每个元素进行组合的 Modifier 的即时组合。

作用域:任意
Modifier.dragAndDropSource(
    transferData: (Offset) -> DragAndDropTransferData?
)

一个 Modifier,允许将应用它的元素视为拖放操作的来源。

作用域:任意
@ExperimentalFoundationApi
Modifier. dragAndDropSource(
    drawDragDecoration: DrawScope.() -> Unit,
    block: suspend DragAndDropSourceScope.() -> Unit
)

此函数已废弃。已由重载替换为用于获取传输数据的回调,启动检测由 Compose 自行执行

作用域:任意
Modifier.dragAndDropSource(
    drawDragDecoration: DrawScope.() -> Unit,
    transferData: (Offset) -> DragAndDropTransferData?
)

一个 Modifier,允许将应用它的元素视为拖放操作的来源。

作用域:任意
Modifier.dragAndDropTarget(
    shouldStartDragAndDrop: (startEvent: DragAndDropEvent) -> Boolean,
    target: DragAndDropTarget
)

允许通过拖放手势来接收内容的修饰符。

作用域:任意

此函数已废弃。请使用 systemGestureExclusion

作用域:Any

此函数已废弃。请使用 systemGestureExclusion

作用域:任意
Modifier.handwritingDetector(callback: () -> Unit)

将某个元素配置为充当手写检测器,用于检测触控笔手写内容,并将对识别出的文本的处理委托给其他元素。

作用域:任意

将某个元素配置为充当触控笔手写处理程序,该处理程序可以处理手写会话(由手写检测器上的触控笔手写触发)中的文本输入。

作用域:任意
Modifier.hoverable(
    interactionSource: MutableInteractionSource,
    enabled: Boolean
)

将组件配置为可通过指针进入/退出事件悬停。

作用域:任意
inline
Modifier. inspectable(
    noinline inspectorInfo: InspectorInfo.() -> Unit,
    factory: Modifier.() -> Modifier
)

此函数已废弃。此 API 会创建更多不必要的修饰符失效,因此不建议使用。

作用域:任意
Modifier.approachLayout(
    isMeasurementApproachInProgress: (lookaheadSize: IntSize) -> Boolean,
    isPlacementApproachInProgress: Placeable.PlacementScope.(lookaheadCoordinates: LayoutCoordinates) -> Boolean,
    approachMeasure: ApproachMeasureScope.(measurable: Measurable, constraints: Constraints) -> MeasureResult
)

创建一个方法布局,旨在帮助逐步接近先行传递中计算的目标布局。

作用域:任意
Modifier.magnifier(
    sourceCenter: Density.() -> Offset,
    magnifierCenter: (Density.() -> Offset)?,
    onSizeChanged: ((DpSize) -> Unit)?,
    zoom: Float,
    size: DpSize,
    cornerRadius: Dp,
    elevation: Dp,
    clip: Boolean
)

显示 Magnifier widget,以显示相对于当前布局节点而言在 sourceCenter 处内容的放大版。

作用域:Any

该修饰符可用于使用由布局树中的其他修饰符(位于此修饰符的左侧或上方)提供的 ModifierLocal

作用域:Any
<T : Any?> Modifier.modifierLocalProvider(
    key: ProvidableModifierLocal<T>,
    value: () -> T
)

该修饰符可用于提供可被其他修饰符(位于该修饰符的右侧或者是该修饰符附加到的布局节点的子项)读取的 ModifierLocal

作用域:任意
Modifier.onLayoutRectChanged(
    throttleMillis: Long,
    debounceMillis: Long,
    callback: (RelativeLayoutBounds) -> Unit
)

根据此布局节点相对于组合根坐标系的位置,以及屏幕坐标和窗口坐标,调用 callback

作用域:任意

在放置父级 LayoutModifier 和父布局之后以及放置子级 LayoutModifier 之前,调用 onPlaced

作用域:任意
@ExperimentalWearMaterialApi
@Composable
Modifier.placeholder(
    placeholderState: PlaceholderState,
    shape: Shape,
    color: Color
)

在可组合项的顶部绘制一个占位符形状,并为擦除效果添加动画效果以移除占位符。

作用域:任意
@Composable
Modifier.placeholder(
    placeholderState: PlaceholderState,
    shape: Shape,
    color: Color
)

在可组合项的顶部绘制一个占位符形状,并为擦除效果添加动画效果以移除占位符。

作用域:任意
@ExperimentalWearMaterialApi
@Composable
Modifier.placeholderShimmer(
    placeholderState: PlaceholderState,
    shape: Shape,
    color: Color
)

用于在组件上绘制占位符闪光的修饰符。

作用域:任意
@Composable
Modifier.placeholderShimmer(
    placeholderState: PlaceholderState,
    shape: Shape,
    color: Color
)

用于在组件上绘制占位符闪光的修饰符。

作用域:任意
Modifier.stylusHoverIcon(
    icon: PointerIcon,
    overrideDescendants: Boolean,
    touchBoundsExpansion: DpTouchBoundsExpansion?
)

该修饰符可让开发者定义当触控笔悬停在元素上时要显示的指针图标。

作用域:任意
Modifier.motionEventSpy(watcher: (motionEvent: MotionEvent) -> Unit)

使用布局区域或任何子级 pointerInput 接收的每个 MotionEvent 调用 watcher

作用域:任意

将布局矩形标记为首选避开悬浮窗口。

作用域:任意

在本地布局坐标内标记一个希望避开浮动窗口的矩形。

作用域:任意

此修饰符用于转换位置,并根据给定的 PullRefreshState 缩放下拉刷新指示器的大小。

作用域:任意

用于向 state 提供滚动事件的嵌套滚动修饰符。

作用域:任意
@ExperimentalMaterialApi
Modifier.pullRefresh(
    onPull: (pullDelta: Float) -> Float,
    onRelease: suspend (flingVelocity: Float) -> Float,
    enabled: Boolean
)

嵌套滚动修饰符,可提供 onPullonRelease 回调,以帮助构建自定义拉取刷新组件。

作用域:任意
@ExperimentalMaterial3Api
Modifier.pullToRefresh(
    isRefreshing: Boolean,
    state: PullToRefreshState,
    enabled: Boolean,
    threshold: Dp,
    onRefresh: () -> Unit
)

一个修饰符,用于向容器添加嵌套滚动以支持下拉刷新手势。

作用域:任意

将当前节点和任何子节点配置为内容接收器。

作用域:任意
Modifier.sensitiveContent(isContentSensitive: Boolean)

此修饰符会提示可组合项会在屏幕上呈现敏感内容(例如用户名、密码、信用卡等),因此在支持的环境中共享屏幕时,应保护内容。

作用域:任意
Modifier.onInterceptKeyBeforeSoftKeyboard(
    onInterceptKeyBeforeSoftKeyboard: (KeyEvent) -> Boolean
)

将此 modifier 添加到组件的 modifier 参数中后,它可以在硬件按键事件发送到软件键盘之前拦截这些事件。

作用域:任意
Modifier.onPreInterceptKeyBeforeSoftKeyboard(
    onPreInterceptKeyBeforeSoftKeyboard: (KeyEvent) -> Boolean
)

将此 modifier 添加到组件的 modifier 参数中后,它可以在硬件按键事件发送到软件键盘之前拦截这些事件。

作用域:任意
Modifier. edgeSwipeToDismiss(
    swipeToDismissBoxState: SwipeToDismissBoxState,
    edgeWidth: Dp
)

此函数已废弃。ShelToDismiss 已迁移到 androidx.wear.compose.foundation。

作用域:任意

从系统手势中排除布局矩形。

作用域:Any

从系统手势中排除局部布局坐标中的矩形。

作用域:Any

使用尚未被类似于 windowInsetsPadding 的其他边衬区修饰符使用的边衬区,而无需添加任何内边距。

作用域:Any

paddingValues 用作边衬区,就像添加了内边距而不考虑边衬区。

作用域:Any
Modifier.onConsumedWindowInsetsChanged(
    block: (consumedWindowInsets: WindowInsets) -> Unit
)

使用由 consumeWindowInsets 或其中一个内边距修饰符(如 imePadding)使用的 WindowInsets 调用 block

作用域:任意

此操作会根据大小和位置重新计算 WindowInsets

此函数已废弃。使用接受 ExposedDropdownMenuAnchorType 和 enabled 参数的重载

abstract
Modifier.menuAnchor(
    type: ExposedDropdownMenuAnchorType,
    enabled: Boolean
)

应应用于 ExposedDropdownMenuBoxScope 内的元素(通常是文本字段或文本字段中的图标)的修饰符。