如何删除 EditText 指示符下面的下划线?

最近我不得不改变 EditText 指示器的颜色,在这之后,一条奇怪的线开始出现在指示器的下方。我怎么才能移除它?我所做的代码如下。

enter image description here

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#4FB6E1">


<br.com.edsilfer.kiwi.loading.CircularProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
app:colorLine="#4e2972"/>


<pl.droidsonroids.gif.GifTextView
android:id="@+id/flying_charizard"
android:layout_width="100dip"
android:layout_height="70dip"
android:layout_above="@+id/login_cluster"
android:layout_margin="15dip"
android:background="@drawable/flying_charizard"/>


<android.support.v7.widget.CardView
android:id="@+id/login_cluster"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginLeft="15dip"
android:layout_marginRight="15dip"
android:elevation="4dip"
card_view:cardUseCompatPadding="true">


<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="10dip"
android:paddingLeft="10dip"
android:paddingRight="10dip">


<include layout="@layout/rsc_util_remove_act_edittext_focus"/>


<EditText
android:id="@+id/email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="E-mail"
android:imeOptions="actionNext"
android:inputType="text"
android:textColor="@color/textSecondary"
android:textColorHint="@color/textSecondary"
android:theme="@style/CustomEditText"/>


<EditText
android:id="@+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dip"
android:hint="Password"
android:imeOptions="actionGo"
android:inputType="textPassword"
android:fontFamily="sans-serif"
android:textColor="@color/textSecondary"
android:textColorHint="@color/textSecondary"
android:theme="@style/CustomEditText"/>




<com.gc.materialdesign.views.ButtonRectangle
android:id="@+id/login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="15dip"
android:background="@color/textSecondary"
android:text="@string/act_login_login"/>


<com.gc.materialdesign.views.ButtonFlat
android:id="@+id/register"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dip"
android:background="@color/textSecondary"
android:text="@string/act_login_create_account"/>


<com.gc.materialdesign.views.ButtonFlat
android:id="@+id/forgotPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="@color/textSecondary"
android:text="@string/act_login_forgot_password"/>


<TextView
android:id="@+id/copyright"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="10dip"
android:layout_marginTop="5dip"
android:alpha="0.7"
android:text="@string/act_login_copyright"
android:textAlignment="center"
android:textColor="@color/textSecondary"
android:textColorHint="@color/textSecondary"
android:textSize="@dimen/textH4"
android:textStyle="bold"/>
</LinearLayout>
</android.support.v7.widget.CardView>


<pl.droidsonroids.gif.GifTextView
android:id="@+id/man_running"
android:layout_width="60dip"
android:layout_height="70dip"
android:layout_alignParentBottom="true"
android:layout_margin="5dip"
android:background="@drawable/man_running"
android:elevation="1dp"/>


<pl.droidsonroids.gif.GifTextView
android:id="@+id/background"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="@drawable/login_background"/>
</RelativeLayout>

Styles.xml

<style name="Theme.AppCompat.Light.NoActionBar.FullScreen" parent="@style/Theme.AppCompat.Light">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">@null</item>
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>


<style name="CustomEditText" parent="Widget.AppCompat.EditText">
<item name="colorControlNormal">@color/colorPrimaryDark</item>
<item name="colorControlActivated">@color/colorPrimaryDark</item>
<item name="colorControlHighlight">@color/colorPrimaryDark</item>
</style>
131938 次浏览

getText()之前使用 edittext.clearComposingText();,在 .xml中可以使用 android:inputType="text|textNoSuggestions"

像这样做背景 编辑文本的 android:background="@null"

EditTextbackground颜色设置为白色。

你可以设置你的屏幕背景颜色为 EditText背景,如果屏幕背景颜色和 EditText背景颜色相同意味着 EditText下划线将不可见。

android:background="#FFFFFF"

setColorFilter()在 API 级别5及以下不起作用。一种方法是使用 setBackgroundColor(TRANSPARENT color)和使用 clearColorFilter()去除它。

安卓: 背景 = “@安卓: 颜色/透明”

还可以为 EditText 定义一个 STYLE,以便可以重新组合所有公共属性。如果您需要编辑多个需要具有该行为的文本,那么它非常强大

将代码放在 res/values/styles.xml 中

<style name="MyEditTextStyle" parent="@android:style/TextAppearance.Widget.EditText">
<item name="android:background">@color/transparence</item> //NO UNDERBAR
<item name="android:maxLines">1</item>
<item name="android:height">28dp</item> //COMMON HEIGHT
</style>

在此之后,您只需要在 EditText 中调用它

               <EditText
android:id="@+id/edit1"
style="@style/MyEditTextStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<EditText
android:id="@+id/edit2"
style="@style/MyEditTextStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

程序上我是这样做的:

editText.setBackground(null);

我有同样的问题显示在 OP 的屏幕截图。接受的答案中描述的解决方案只需删除要自定义的下划线。从 Widget.AppCompat.EditText而不是 主题继承 风格是可以的。修复方法是从 CustomEditText 中删除继承:

<style name="CustomEditText"><!-- parent removed -->
<item name="colorControlNormal">@color/colorPrimaryDark</item>
<item name="colorControlActivated">@color/colorPrimaryDark</item>
<item name="colorControlHighlight">@color/colorPrimaryDark</item>
</style>

学分归这个 回答

如果 android:background="@null"不起作用-试着将它与 android:inputType="text|textNoSuggestions"结合起来

全景:

    <EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@null"
android:inputType="text|textNoSuggestions" />

如果您使用的是 材料组件 TextInputLayout,将背景颜色设置为其他颜色并不会去除下划线,解决方案是像这样设置 BoxBackgroundMode(kotlin) : myTextInputLayout.boxBackgroundMode = TextInputLayout.BOX_BACKGROUND_NONE

或 xml 格式: app:boxBackgroundMode="none"

我认为这个组件的更改是为了使下划线“工作”与自定义的背景颜色