如何删除EditText指标下方的下划线?

Edg*_*des 43 android

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

在此输入图像描述

<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>
Run Code Online (Sandbox Code Playgroud)

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>
Run Code Online (Sandbox Code Playgroud)

Jin*_*cis 46

制作类似于android:background="@null"editText的背景

  • 如果您已经使用了自定义背景可绘制对象,则无法使用此解决方案。 (4认同)
  • 我认为如果使用自定义背景,则编辑文本下方的行将不可见。 (2认同)
  • 不,我使用自定义背景可绘制。但仍然有下划线,这在这种情况下不起作用 (2认同)

Gab*_*den 16

如果您使用的是材质组件 TextInputLayout,则将背景颜色设置为其他颜色并不能消除下划线,解决方案是设置BoxBackgroundMode如下所示(kotlin): myTextInputLayout.boxBackgroundMode = TextInputLayout.BOX_BACKGROUND_NONE

或在xml中: app:boxBackgroundMode="none"

我认为对组件进行此更改是为了使下划线“工作”具有自定义背景色

  • 哇!在此处提到的所有解决方法中,`app:boxBackgroundMode="none"` 也可以使用自定义背景来解决问题!荣誉。作为参考,我使用了由 androidX 的“TextInputLayout”包裹的材质“TextInputEditText” (2认同)

Yat*_*ish 11

background颜色设置EditText为白色.

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

android:background="#FFFFFF" 
Run Code Online (Sandbox Code Playgroud)


Hir*_*ren 10

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

  • 线仍然在那里,甚至使用... (5认同)

Mak*_*vin 8

android:background="@android:颜色/透明"


Edg*_*ich 7

如果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" />
Run Code Online (Sandbox Code Playgroud)


ch1*_*mob 6

以编程方式我这样做:

editText.setBackground(null);
Run Code Online (Sandbox Code Playgroud)

  • 也可以通过 xml 来完成 - android:background="@null" (2认同)