You need to enable JavaScript to run this app. Android开发中如何移除TextInputLayout或TextInputEditText的输入下划线
优惠活动
大模型
产品
解决方案
定价
更多

Android开发中如何移除TextInputLayout或TextInputEditText的输入下划线

我想要移除输入框的下划线

展示Android平台下输入框下划线的示例图片
以下是我的相关布局代码:

<com.google.android.material.textfield.TextInputLayout
    android:id="@+id/textInputLayoutName"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="60dp"
    android:layout_marginStart="5dp"
    android:layout_marginEnd="5dp"
    app:boxCornerRadiusTopStart="20dp"
    app:boxCornerRadiusTopEnd="20dp"
    app:boxCornerRadiusBottomEnd="20dp"
    app:boxCornerRadiusBottomStart="20dp">

    <com.google.android.material.textfield.TextInputEditText
        android:id="@+id/textInputEditTextName"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="@string/register_hint_name"
        android:inputType="text"
        android:textColor="@color/black" />

</com.google.android.material.textfield.TextInputLayout>

实现方法

在现有TextInputLayout标签中追加对应属性即可,无需修改其他布局逻辑:

  • 如果你需要彻底移除所有TextInputLayout自带的装饰效果(包括下划线、默认填充背景、聚焦态线条动画),直接追加属性:
    app:boxBackgroundMode="none"
    
    设置完成后,TextInputLayout不会渲染任何自带的装饰图层,输入框表现和原生普通EditText完全一致,不会出现任何多余的下划线元素。
  • 如果你需要保留已经配置好的20dp圆角填充背景,只隐藏底部下划线和边框线条,依次追加以下属性:
    <!-- 将所有交互状态下的边框颜色设为全透明 -->
    app:boxStrokeColor="@android:color/transparent"
    <!-- 将默认、聚焦状态下的边框线宽设为0 -->
    app:boxStrokeWidth="0dp"
    app:boxStrokeWidthFocused="0dp"
    
    这种设置下,自定义的圆角背景效果会完整保留,所有下划线、边框类的线条元素会完全隐藏。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.11.13 00:45:03