Android Ice Cream Sandwich Edittext: Disabling Spe

2019-01-30 23:53发布

Whilst testing on the Android Emulator running Android 4.0 (Ice Cream Sandwich), I have noticed that the Edittext does some quite strange things.

Firstly, it underlines every word identified as "misspelt" in red. How do I disable this? Secondly, although in the layout XML I have specified android:scrollHorizontally="true" word-wrap is enabled: how do I disable this as well? Here is the Layout XML code for the Edittext:

    <EditText
        android:id="@+id/editor"
        android:layout_width="40dp"
        android:layout_height="fill_parent"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/toolbar"
        android:layout_toRightOf="@+id/toolbarleft"
        android:paddingBottom="0dp"
        android:paddingRight="0dp"
        android:scrollHorizontally="true"
        android:text=""
        android:inputType="textMultiLine" >

        <requestFocus />
    </Edittext>

Here is an example of the spell checker I need to disable:

Demonstration of Spell-Checker http://www.abstract-thoughts.com/wp-content/uploads/2011/10/spell.jpg

Thanks very much!

7条回答
劳资没心,怎么记你
2楼-- · 2019-01-30 23:55

In your Java class you can add to the Edittext object...

  wire1type = (EditText)findViewById(R.id.wire1type);
  wire1type.setInputType( ~(InputType.TYPE_TEXT_FLAG_AUTO_CORRECT) );

This clears out the autocorrect flag and will work in API 4.

查看更多
Root(大扎)
3楼-- · 2019-01-31 00:01

remove android:inputType="" and all should be well.

查看更多
Emotional °昔
4楼-- · 2019-01-31 00:05

Disabling the spell checker for general text input via code:

mEditText.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
查看更多
可以哭但决不认输i
5楼-- · 2019-01-31 00:07

Disabling Spell-Checking
In order to get rid of spell checking you must specify the EditText's InputType in the XML as the following:

android:inputType="textNoSuggestions"

However, my EditText needed also to be multiline, so I have added the following line to the EditText's XML:

android:inputType="textMultiLine|textNoSuggestions"

Disabling Word-Wrap
As noted, the XML attribute android:scrollHorizontally="true" does not work. However, strangely, if it is done through Java it does work. Here is the necessary code to achieve no word wrapping:

mEditText.setHorizontallyScrolling(true);

查看更多
SAY GOODBYE
6楼-- · 2019-01-31 00:16

Disabling Spell-Checking in EditText.

In Android 4.0+ sometimes I get a red underline in my Textview so i add the property ...

android:inputType="textNoSuggestions" 

textNoSuggestions: to indicate that the IME should not show any dictionary-based word suggestions.

Here is a list of possible properties that we can define in : android:inputType

Disabling Word-Wrap

remember that the property android:scrollHorizontally="true" doesn't work, so this is the solution:

mEditText.setHorizontallyScrolling(true);
查看更多
时光不老,我们不散
7楼-- · 2019-01-31 00:18

To disable line wrapping you have to wrap (pun not intended) your EditText with an HorizontalScrollView and set your layout_width to match_parent.

查看更多
登录 后发表回答