输入时,Android edittext会加下划线

时间:2016-02-10 18:27:20

标签: android android-edittext android-keypad android-inputtype

在Android中输入编辑文本字段时,我需要删除下划线。对于第一个名称编辑文本,第一个字母应该是大写,以便我给出textCapSentences,但在我的情况下,我在edittext字段中看到下划线。如何删除?

我已经尝试了textFilter|textNoSuggestions|textCapSentences

的所有组合

我的名字编辑文字:

    <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" />

我的屏幕:

enter image description here

6 个答案:

答案 0 :(得分:5)

android:inputType="textVisiblePassword"禁用文本自动更正

答案 1 :(得分:3)

这是强调每个单词的建议。试试这个:

android:inputType="textNoSuggestions"

答案 2 :(得分:1)

使用此:<div class="wrapper"> <div class="box1"></div> <div class="box2"></div> <div class="box3"></div> </div>

答案 3 :(得分:1)

没有其他答案对我有用。添加下划线以在书写时建议单词。这是通过键盘应用程序(在我的情况下为Gboard)上的设置启用的。

因此至少可以选择三个选项:

  • 什么也不做,因为这是外部应用程序(Gboard)上的设置,应该由用户来处理。

  • 要求用户禁用它,并显示说明以说明如何执行此操作。这是:要从设置应用程序或打开的键盘中导航到gboard设置,然后单击设置按钮,然后转到“文本/拼写校正”或类似设置并禁用第一个开关:显示建议栏

  • 自行删除。当Gboard在EditTexts中将UnderlineSpan添加到EditableText时,您可以先将其删除。下划线是由Gboard在onTextChanged和afterTextChanged之间添加的,因此我必须在afterTextChanged方法中将其删除。

    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);
             }
    
             ...
         }
    });
    

如果需要保留任何其他UnderlineSpan,则可以将此解决方案与此解决方案混合使用:https://stackoverflow.com/a/47704299/6552016

答案 4 :(得分:1)

结合您的答案,这实际上对我有效:

android:inputType="textVisiblePassword|textNoSuggestions"

答案 5 :(得分:0)

将其放入.xml文件的编辑文本布局中

android:background =“ @ null”

相关问题