Android edittext is underlined when typing

后端 未结 6 1880
抹茶落季
抹茶落季 2021-01-05 02:46

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<

相关标签:
6条回答
  • 2021-01-05 03:20

    put this in edit text layout in your .xml file

    android:background="@null"

    0 讨论(0)
  • 2021-01-05 03:30

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

    0 讨论(0)
  • 2021-01-05 03:31

    Combining your answers this is what actually works for me:

    android:inputType="textVisiblePassword|textNoSuggestions"
    
    0 讨论(0)
  • 2021-01-05 03:34

    android:inputType="textVisiblePassword" disabling text autocorrection

    0 讨论(0)
  • 2021-01-05 03:34

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

    android:inputType="textNoSuggestions"
    
    0 讨论(0)
  • 2021-01-05 03:42

    None of the other answers were useful for me. This underline is added to suggest words when writing. 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 the 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

    0 讨论(0)
提交回复
热议问题