Newstrong's 博客

Kratos
专注于用户阅读体验的响应式博客主题
  1. 首页
  2. 未分类
  3. 正文

自定义的BasicTextField,只包含 BasicTextField 的基本功能和 placeHolder

2024年9月25日 3点热度 0人点赞 0条评论

/**
 * 自定义的BasicTextField,只包含 @see BasicTextField 的基本功能和 placeHolder
 *
 * @param placeHolder 没有输入的占位符
 */
@Composable
fun CustomBasicTextField(
  value: String,
  onValueChange: (String) -> Unit,
  placeHolder: (@Composable BoxScope.() -> Unit)? = null,
  modifier: Modifier = Modifier,
  enabled: Boolean = true,
  readOnly: Boolean = false,
  textStyle: TextStyle = TextStyle.Default,
  keyboardOptions: KeyboardOptions = KeyboardOptions.Default,
  keyboardActions: KeyboardActions = KeyboardActions.Default,
  singleLine: Boolean = false,
  maxLines: Int = if (singleLine) 1 else Int.MAX_VALUE,
  minLines: Int = 1,
  visualTransformation: VisualTransformation = VisualTransformation.None,
  onTextLayout: (TextLayoutResult) -> Unit = {},
  interactionSource: MutableInteractionSource? = null,
  cursorBrush: Brush = SolidColor(Color.Black),
  decorationBox: @Composable (innerTextField: @Composable () -> Unit) -> Unit =
    @Composable { innerTextField -> innerTextField() }
) {
  Box(modifier = modifier){
    if (value.isEmpty() && placeHolder != null) placeHolder.invoke(this)
    BasicTextField(
      value = value,
      onValueChange = onValueChange,
      singleLine = singleLine,
      enabled = enabled,
      modifier = Modifier,
      cursorBrush = cursorBrush,
        textStyle=textStyle,
      readOnly = readOnly,
      keyboardOptions = keyboardOptions,
      keyboardActions = keyboardActions,
      maxLines = maxLines,
      minLines = minLines,
      interactionSource = interactionSource,
      visualTransformation = visualTransformation,
      onTextLayout = onTextLayout,
      decorationBox = decorationBox
    )
  }
}
标签: 暂无
最后更新:2026年6月22日

newstrong

这个人很懒,什么都没留下

点赞
< 上一篇
下一篇 >

文章评论

razz evil exclaim smile redface biggrin eek confused idea lol mad twisted rolleyes wink cool arrow neutral cry mrgreen drooling persevering
取消回复

归档

  • 2026 年 6 月
  • 2026 年 1 月
  • 2025 年 3 月
  • 2024 年 10 月
  • 2024 年 9 月
  • 2024 年 8 月
  • 2021 年 4 月
  • 2020 年 5 月

分类

  • Android
  • git
  • 性能优化
  • 未分类

COPYRIGHT © 2026 Newstrong's 博客. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang