Underline under cursor

2019-02-20 09:09发布

问题:

I have implemented Custom edittext, with custom style :

<android.support.design.widget.TextInputLayout

            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="Username"
            android:textColorHint="@color/white"
            app:hintAnimationEnabled="true"
            app:hintTextAppearance="@style/TExtAppearance"
            >

            <com.app.farmtrace.fieldagent.CustomView.EditText_SemiBold
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textColor="@color/colorAccent"
                android:theme="@style/EditTextStyle"
                android:id="@+id/username"
                android:maxLines="1"
                android:maxLength="50"
                android:inputType="textEmailAddress|textNoSuggestions"
                android:nextFocusDown="@+id/password"
                />

        </android.support.design.widget.TextInputLayout>

And this is the screen :

there is just the cursor and now when i again select the cursor i get this :

I dont want the yellow underline below the cursor.

This is tested in Moto g4 with android 7.0.

<style name="TExtAppearance">
    <item name="android:textColor">@color/white</item>
    <item name="android:textColorHighlight">@color/white</item>
    <item name="android:textColorHint">@color/white</item>
    <item name="android:textColorLink">@color/white</item>
    <item name="android:textSize">16sp</item>
    </style>



<style name="EditTextStyle" parent="Widget.AppCompat.EditText">
        <item name="colorControlNormal">@color/white</item>
        <item name="colorControlActivated">@color/colorAccent</item>
        <!--<item name="colorControlHighlight">@color/colorAccent</item>-->
    </style>

Edit Also Getting underline on error if i seterror and text not visible of error :

回答1:

I ran into the same issue. I was able to get rid of the cursor underline by removing the Widget.AppCompat.EditText parent style from my TextInputEditTexts' custom style. In other words, I changed my TextInputEditTexts' style from this:

<style name="MyEditTextStyle" parent="Widget.AppCompat.EditText">
        ...
</style>

to this:

<style name="MyEditTextStyle">
        ...
</style>

Example of one of my TextInputEditTexts referencing the style:

<android.support.design.widget.TextInputEditText
    android:id="@+id/edit_username"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/MyEditTextStyle"/>


回答2:

Try to set inputType="textNoSuggestions" your edit text in android

     android:inputType="textNoSuggestions"


回答3:

try to set background with the help of drawable

make a new drawable file eg. et_back.xml and make a background/shape

then use it as background in your edit text ...

eg. let it be your drawable.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke
    android:width="2dp"
    android:color="#000000" />
</shape>

and your edittext be :

<EditText
    //other attribute/properties
    android:background="@drawable/drawable_name"        
    />