You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React Native TextInput聚焦时白色条如何移除?underlineColor设置无效

React Native Paper MD3DarkTheme下TextInput聚焦白色条问题解决

在使用react-native-paper的MD3DarkTheme时,遇到TextInput组件聚焦状态下会显示白色下划线的问题,尝试设置underlineColor="transparent"和underlineColorAndroid="transparent"后,问题依然存在。

原组件代码

<TextInput
  style={[styles.input, styles.textArea]}
  placeholder="Raison de l'absence"
  value={reason}
  onChangeText={setReason}
  underlineColor="transparent"
  underlineColorAndroid="transparent"
  autoFocus={false}
/>;

原样式代码

textArea: {
    borderColor: 'transparent',
},

input: {
    width: '100%',
    height: 40,
    borderWidth: 1,
    borderRadius: 5,
    marginBottom: 15,
    paddingLeft: 10,
    justifyContent: 'center',
    color: PaperDarkTheme.colors.text,
},

解决方法

查看react-native-paper文档后发现,聚焦状态下的下划线由activeUnderlineColor属性控制,仅设置underlineColor无法覆盖聚焦时的样式。只需给TextInput添加activeUnderlineColor="transparent"(或与当前主题背景色一致的颜色)即可解决问题。

修改后的组件代码示例:

<TextInput
  style={[styles.input, styles.textArea]}
  placeholder="Raison de l'absence"
  value={reason}
  onChangeText={setReason}
  underlineColor="transparent"
  underlineColorAndroid="transparent"
  activeUnderlineColor="transparent"
  autoFocus={false}
/>;

内容的提问来源于stack exchange,提问作者Czsyn

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.04 08:33:21