Android edittext is underlined when typing

2019-05-04 19:37发布

I need to removed underline when type in edit text field in Android. For the first name edit text first letter should be capital so that I have given textCapSentences, but in my case I see underline in edittext fields. how to remove that?

I have tried all the combination of textFilter|textNoSuggestions|textCapSentences

its my first name edit text:

    <EditText
        android:id="@+id/signup_lname"
        android:layout_width="match_parent"
        android:layout_height="60dp"
        android:background="@color/signup_layer_bg2"
        android:ems="10"
        android:gravity="center"
        android:hint="@string/signup_lname"
        android:imeOptions="actionDone"
        android:inputType="textFilter|textNoSuggestions|textCapSentences"
        android:paddingLeft="5dp"
        android:paddingRight="5dp"
        android:singleLine="true"
        android:textColor="@android:color/white"
        android:textColorHint="@android:color/white"
        android:textCursorDrawable="@drawable/custom_cursor" />

My screen:

enter image description here

4条回答
够拽才男人
2楼-- · 2019-05-04 20:01

Use this: android:background="@android:color/transparent"

查看更多
相关推荐>>
3楼-- · 2019-05-04 20:11

It's the suggestions that are underlining each word. Try this:

android:inputType="textNoSuggestions"
查看更多
等我变得足够好
4楼-- · 2019-05-04 20:17

Non of the other answers were useful for me. This underline is added to suggest words when writting. This is enabled by a setting on your keyboard app (Gboard in my case).

So there are at least three options you can do:

  • Do nothing as this is a setting on an external app (Gboard) and is the user who should handle it.

  • Ask the user to disable it and show instructions to explain how to do it. This is: To navigate to gboard settings from settings app or also from an opened keyboard and click on settings button, then go to "text/spell correction" or similar and disable the first switch: Show suggestion strip

  • Remove it by your self. As Gboard adds an UnderlineSpan to the EditableText in EditTexts you can remove it just first looking for it. The underline is added by Gboard at some point between onTextChanged and afterTextChanged so I had to remove it on afterTextChanged method.

    editText.addTextChangedListener(new TextWatcher() {
         @Override
         public void beforeTextChanged(CharSequence s, int start, int count, int after) {
         }
    
         @Override
         public void onTextChanged(CharSequence s, int start, int before, int count) {
         }
    
         @Override
         public void afterTextChanged(Editable s) {
             for (UnderlineSpan span : s.getSpans(0, s.length(), UnderlineSpan.class)) {
                 s.removeSpan(span);
             }
    
             ...
         }
    });
    

If you need to keep any other UnderlineSpan you could mix this solution with this one: https://stackoverflow.com/a/47704299/6552016

查看更多
老娘就宠你
5楼-- · 2019-05-04 20:27

android:inputType="textVisiblePassword" disabling text autocorrection

查看更多
登录 后发表回答