Android冰淇淋三明治Edittext:禁用拼写检查和Word Wrap
在运行Android 4.0(Ice Cream Sandwich)的Android模拟器上进行testing时,我注意到Edittext做了一些很奇怪的事情。
首先,它强调每一个被识别为红色的“拼写错误”的单词。 我如何禁用这个? 其次,尽pipe在布局XML中,我已经指定了android:scrollHorizontally="true" word-wrap是启用的:我怎么禁用这个呢? 以下是Edittext的布局XML代码: 
  <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> 
这是我需要禁用的拼写检查器的一个例子:
拼写检查器演示http://www.abstract-thoughts.com/wp-content/uploads/2011/10/spell.jpg
非常感谢!
  禁用拼写检查 
 为了摆脱拼写检查,您必须在XML中指定EditText的InputType,如下所示: 
 android:inputType="textNoSuggestions" 
但是,我的EditText也需要多行,所以我在EditText的XML中添加了以下行:
 android:inputType="textMultiLine|textNoSuggestions" 
  禁用Word-Wrap 
 如上所述,XML属性android:scrollHorizontally="true"不起作用。 然而,奇怪的是,如果它是通过Java完成的,它确实有效。 以下是实现无字换行的必要代码: 
 mEditText.setHorizontallyScrolling(true); 
在EditText中禁用拼写检查。
 在Android 4.0+有时我在我的Textview中得到一个红色的下划线,所以我添加属性… 
 android:inputType="textNoSuggestions" 
textNoSuggestions : 指示IME不应显示任何基于字典的单词build议。
这里是我们可以定义的可能的属性列表: android:inputType
禁用Word-Wrap
 请记住属性android:scrollHorizontally="true"不起作用,所以这是解决方法: 
 mEditText.setHorizontallyScrolling(true); 
在你的Java类中,你可以添加到Edittext对象中
  wire1type = (EditText)findViewById(R.id.wire1type); wire1type.setInputType( ~(InputType.TYPE_TEXT_FLAG_AUTO_CORRECT) ); 
这将清除自动更正标志,并将在API 4中工作。
 android:inputType="textMultiLine|textPhonetic" 
为我删除了所有的红色下划线。
 android:inputType="textMultiLine|textNoSuggestions" 
产生编译错误。
我使用Android API 1.6。
禁用拼写检查器以通过代码input一般文本:
 mEditText.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS); 
 删除android:inputType="" ,一切都会好的。 
要禁用换行,你必须用一个HorizontalScrollView来包装(不打算)你的EditText,并将你的layout_width设置为match_parent。