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

以下是我的相关布局代码:
<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自带的装饰效果(包括下划线、默认填充背景、聚焦态线条动画),直接追加属性:
设置完成后,TextInputLayout不会渲染任何自带的装饰图层,输入框表现和原生普通EditText完全一致,不会出现任何多余的下划线元素。app:boxBackgroundMode="none" - 如果你需要保留已经配置好的20dp圆角填充背景,只隐藏底部下划线和边框线条,依次追加以下属性:
这种设置下,自定义的圆角背景效果会完整保留,所有下划线、边框类的线条元素会完全隐藏。<!-- 将所有交互状态下的边框颜色设为全透明 --> app:boxStrokeColor="@android:color/transparent" <!-- 将默认、聚焦状态下的边框线宽设为0 --> app:boxStrokeWidth="0dp" app:boxStrokeWidthFocused="0dp"
内容的提问来源于stack exchange,提问作者Nikola
相关产品推荐
相关产品推荐

