43

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
(source: abstract-thoughts.com)

Thanks very much!

Community
  • 1
  • 1
Henry Thompson
  • 2,441
  • 3
  • 23
  • 31

7 Answers7

87

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

Henry Thompson
  • 2,441
  • 3
  • 23
  • 31
  • 1
    It is worth noting that in 4.4 the scrollHorizontally XML attribute does work. Not sure which API level this was fixed in but it is fixed. – ian.shaun.thomas Dec 05 '13 at 15:07
34

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);
Jorgesys
  • 124,308
  • 23
  • 334
  • 268
  • 1
    Thanks for that. Unfortunately I have already worked that out (if you see the question I've asked, I updated it so it says so). Thanks anyway! – Henry Thompson Feb 22 '12 at 19:32
  • 2
    @HenryThompson Bundling two questions into one is bad practice on StackOverflow. And your question (which I just read) still poses the question that Elenasys answers. It's just that you 'hid' the answer inside the sample code but didn't call attention to it, leading us to believe that your code didn't work for you. – Andrew Arnott Feb 06 '14 at 15:10
  • 1
    @HenryThompson a lot of answers posted before you "answered" your own question. – Jorgesys Feb 06 '14 at 16:14
  • @AndrewArnott I'm sorry if it does go against StackOverflow guidelines... however, they have been answered and that is too late now. Elenasys's answer only answered one of those answers, hence why it was not accepted - it did not answer the point about word wrapping, and indeed none of the other did either. I also do not understand that bit about hiding the answer? – Henry Thompson Feb 06 '14 at 22:28
  • @Elenasys Yes, but none of the previous answers satisfactorily answered my questions, hence why I accepted my own answer. I'm sorry your answer did not get accepted, as it is true that it was correct - however, it did only answer half of my questions, hence why it was not accepted. – Henry Thompson Feb 06 '14 at 22:29
  • 1
    @AndrewArnott I see what you mean about hiding the answer - that wasn't in the original question, someone's edited it... have a look through the edit history. I've reverted the code back so it makes more sense – Henry Thompson Feb 06 '14 at 22:31
9

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.

user823014
  • 91
  • 1
  • 2
  • This is the only correct answer. Other answers (``textNoSuggestions``) have the undesired sideeffect of also disabling word prediction on the soft keyboard (e.g. Swyft Type) – zyamys Jan 12 '16 at 19:25
7
android:inputType="textMultiLine|textPhonetic"

removed all red underlines for me.

android:inputType="textMultiLine|textNoSuggestions"

produces compilation error.

I use Android API 1.6.

bancer
  • 7,475
  • 7
  • 39
  • 58
  • Yes it appears textNoSuggestions is not supported until later on. My app supports Android 2.1 upwards so it is not a problem. – Henry Thompson Apr 27 '12 at 21:07
5

Disabling the spell checker for general text input via code:

mEditText.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
Mohsen Afshin
  • 13,273
  • 10
  • 65
  • 90
0

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

Vic Vuci
  • 6,993
  • 6
  • 55
  • 90
0

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

André Restivo
  • 1,271
  • 14
  • 13
  • I see what you are saying. When I initially started writing this app I used a Scrollview but it made my app ridiculously slow so I would like to avoid using it if at all possible. There must be a way to disable line wrapping on Android 4.0- all other versions of Android have supported it using `android:scrollHorizontally="true"`. If Google have got rid of the ability to turn word wrapping off I find that very strange, and yes, I will have to use ScrollView. Thanks very much for your help anyway! – Henry Thompson Feb 14 '12 at 13:03
  • I have used this answer as, looking around, it seems like the only solution there is. Therefore I will award this the answer. However, if anybody does know any better ways of doing this, I would really appreciate it if they could let me know how to do it! – Henry Thompson Feb 18 '12 at 15:18
  • About ScrollView being slow in ICS: Try disabling hardware acceleration in manifest. Worked for me. – André Restivo Feb 18 '12 at 19:03
  • Related issue for slow TextView scrolling: http://stackoverflow.com/questions/12113623/scrollview-is-extremly-slow-on-ics-android-4-0-when-containing-a-long-textview – ian.shaun.thomas Dec 05 '13 at 15:09