remove additional underline in EditText

前端 未结 5 1083
广开言路
广开言路 2020-12-07 02:40

I have EditText with custom background drawable:

EditText code:



        
相关标签:
5条回答
  • 2020-12-07 03:16

    Use inputType textNoSuggestions in xml.

      <EditText
        android:id="@+id/text"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:inputType="text|textNoSuggestions"/>
    

    InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS is equivalent flag for this using code

    0 讨论(0)
  • 2020-12-07 03:18

    You can set the EditText to have a custom transparent drawable or just use

     android:background="@android:color/transparent".
    
    0 讨论(0)
  • 2020-12-07 03:18

    As per my understanding. Use this in your editText

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

    And If you want to stop Spell Checker for Text which you had typed then use

    android:inputType="textNoSuggestions"
    
    0 讨论(0)
  • 2020-12-07 03:27

    I have seen all the valid answers given above. But at the last try You can something like:

     mEditText.addTextChangedListener(new TextWatcher() {
                @Override
                public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
    
                }
    
                @Override
                public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
    
                }
    
                @Override
                public void afterTextChanged(Editable editable) {
                    new Handler().postDelayed(new Runnable() {
                        @Override
                        public void run() {
                            mEditText.clearComposingText();
                        }
                    },200);
    
    
                }
            });
    

    ClearComposingText method will help you. Hope this helps.

    0 讨论(0)
  • 2020-12-07 03:32

    The underline text styling is applied by the BaseInputConnection of EditText to the text currently being "composed" using the styling applied by the theme attribute android:candidatesTextStyleSpans, which by default is set to the string <u>candidates</u>.

    The text part of the string is ignored, but the style spans are extracted from the string and applied to "composing" text which is the word the user is currently typing, a.o. to indicate that suggestions can be selected or that autocorrect is active.

    You can change that styling (e.g. to use bold or italics instead of underlines), or remove the styling altogether, by setting the theme attribute to a styled or unstyled string:

    <!-- remove styling from composing text-->
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- ... -->
        <item name="android:candidatesTextStyleSpans">candidates</item>
    </style>
    
    <!-- apply bold + italic styling to composing text-->
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- ... -->
        <item name="android:candidatesTextStyleSpans"><b><i>candidates</i></b></item>
    </style>
    

    Caveat: Removing all styling will cause the BaseInputConnection implementation to re-evaluate the theme attribute on every change of text, as the span information is lazy loaded and persisted only if the attribute is set to a styled string. You could alternatively set any other styling as is supported by Html:fromHtml(...), e.g. <span style="color:#000000">...</span> to the default text color, which makes no difference in display.

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