Android Ice Cream Sandwich Edittext: Disabling Spell Check and Word Wrap
W

7

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!

Watchtower answered 25/1, 2012 at 23:24 Comment(0)
W
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);

Watchtower answered 18/8, 2012 at 22:17 Comment(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.Braddy
C
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);
Crosby answered 22/2, 2012 at 17:32 Comment(6)
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!Watchtower
@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.Globuliferous
@HenryThompson a lot of answers posted before you "answered" your own question.Crosby
@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?Watchtower
@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.Watchtower
@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 senseWatchtower
G
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.

Gawk answered 24/4, 2012 at 12:44 Comment(1)
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)Beard
J
7
android:inputType="textMultiLine|textPhonetic"

removed all red underlines for me.

android:inputType="textMultiLine|textNoSuggestions"

produces compilation error.

I use Android API 1.6.

Joust answered 27/4, 2012 at 10:42 Comment(1)
Yes it appears textNoSuggestions is not supported until later on. My app supports Android 2.1 upwards so it is not a problem.Watchtower
S
5

Disabling the spell checker for general text input via code:

mEditText.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
Series answered 22/5, 2013 at 5:46 Comment(0)
I
0

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

Infinitude answered 26/1, 2012 at 0:19 Comment(1)
Sorry that's my mistake- in the actual code I had already got rid of inputType="" and it made no difference.Watchtower
A
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.

Aegrotat answered 14/2, 2012 at 1:53 Comment(4)
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!Watchtower
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!Watchtower
About ScrollView being slow in ICS: Try disabling hardware acceleration in manifest. Worked for me.Beneficial
Related issue for slow TextView scrolling: #12114123Braddy

© 2022 - 2024 — McMap. All rights reserved.