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

Android开发:如何移除EditText的下划线?双下划线问题求助

移除文本下划线的解决方案

黑色下划线处理

黑色下划线一般是文本自身的装饰样式,可通过以下方式移除:

  • XML布局中直接禁用文本装饰:
    android:textDecoration="none"
    
  • 若代码中通过UnderlineSpan添加了下划线,可动态移除:
    Spannable spannable = (Spannable) yourTextView.getText();
    UnderlineSpan[] underlineSpans = spannable.getSpans(0, spannable.length(), UnderlineSpan.class);
    for (UnderlineSpan span : underlineSpans) {
        spannable.removeSpan(span);
    }
    yourTextView.setText(spannable);
    

绿色下划线处理(android:background="@null"无效时)

绿色下划线多为控件背景的默认样式或主题 tint 效果,尝试以下方案:

  1. 替换@null为透明背景:
    android:background="@android:color/transparent"
    
  2. 若控件在TextInputLayout内,需同时关闭布局的边框:
    <com.google.android.material.textfield.TextInputLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:boxStrokeWidth="0dp"
        app:boxStrokeColor="@android:color/transparent">
    
        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@android:color/transparent"/>
    </com.google.android.material.textfield.TextInputLayout>
    
  3. 代码中清除背景 tint 效果:
    yourTextView.setBackgroundTintList(null);
    
  4. 检查是否开启了自动链接,关闭自动链接:
    android:autoLink="none"
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.28 18:50:01