如何去除Android Compose中BasicTextField的下划线?
移除BasicTextField下划线的方法
直接在BasicTextField中添加colors参数,将各类状态下的指示器颜色设为透明即可移除下划线,修改后的代码如下:
BasicTextField( value = bodyText.value, onValueChange = { input -> bodyText.value = input }, modifier = Modifier .fillMaxWidth() .padding(), textStyle = CustomTextStyle.Title9, // 配置颜色隐藏下划线 colors = TextFieldDefaults.colors( focusedIndicatorColor = Color.Transparent, unfocusedIndicatorColor = Color.Transparent, disabledIndicatorColor = Color.Transparent ), decorationBox = { innerTextField -> Row( modifier = Modifier.fillMaxWidth(), verticalAlignment = Alignment.CenterVertically ) { Box { innerTextField() if (bodyText.value.isEmpty()) { Text( "게시글을 적어주세요.", style = CustomTextStyle.Title9, color = CustomColor.Gray ) } } } }, )
BasicTextField的默认下划线其实是内置的指示器组件,通过把聚焦、失焦、禁用这三种状态的指示器颜色都设为透明,就能彻底隐藏下划线,同时不影响其他功能。
内容的提问来源于stack exchange,提问作者HamTory
相关产品推荐
相关产品推荐

