安卓冰激凌三明治Edittext:禁用拼写检查和单词包装

时间:2022-11-09 20:23:12

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

在运行安卓4.0(冰激凌三明治)的安卓模拟器上测试时,我注意到Edittext做了一些非常奇怪的事情。

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:

首先,它强调每一个用红色拼错的词。如何禁用这个?其次,尽管在布局XML中我指定了android: scrollhorizontal =“true”换行是启用的:我如何禁用它?下面是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>

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

拼写检查程序的演示http://www.abstract-thoughts.com/wp-content/uploads/2011/10/spell.jpg

Thanks very much!

非常感谢!

7 个解决方案

#1


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:

禁用拼写检查以摆脱拼写检查,您必须在XML中指定EditText的InputType,如下所示:

android:inputType="textNoSuggestions"

android:inputType = " textNoSuggestions "

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

但是,我的EditText也需要多行,因此我在EditText的XML中添加了如下一行:

android:inputType="textMultiLine|textNoSuggestions"

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:

如前所述,禁用单词包装,XML属性android: scrollhorizontal ="true"不起作用。然而,奇怪的是,如果它是通过Java完成的,那么它就可以工作。以下是实现无词包装的必要代码:

mEditText.setHorizontallyScrolling(true);

mEditText.setHorizontallyScrolling(真正的);

#2


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 4.0+中,有时Textview中会出现红色下划线,因此我添加了属性……

android:inputType="textNoSuggestions" 

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

textNoSuggestions:指示IME不应该显示任何基于字典的词汇建议。

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

下面是我们可以在以下列表中定义的可能属性:android:inputType

Disabling Word-Wrap

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

记住,属性android: scroll水平="true"不工作,所以这是解决方案:

mEditText.setHorizontallyScrolling(true);

#3


9  

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

在Java类中,您可以添加到Edittext对象……

  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.

这将清除自动更正标志,并将在API 4中工作。

#4


7  

android:inputType="textMultiLine|textPhonetic"

removed all red underlines for me.

去掉所有红色下划线。

android:inputType="textMultiLine|textNoSuggestions"

produces compilation error.

产生编译错误。

I use Android API 1.6.

我使用Android API 1.6。

#5


5  

Disabling the spell checker for general text input via code:

通过代码禁用一般文本输入的拼写检查器:

mEditText.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);

#6


0  

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

删除android:inputType=",一切都应该很好。

#7


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.

要禁用行包装,您必须使用HorizontalScrollView将您的EditText包装(pun不打算),并将layout_width设置为match_parent。

#1


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:

禁用拼写检查以摆脱拼写检查,您必须在XML中指定EditText的InputType,如下所示:

android:inputType="textNoSuggestions"

android:inputType = " textNoSuggestions "

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

但是,我的EditText也需要多行,因此我在EditText的XML中添加了如下一行:

android:inputType="textMultiLine|textNoSuggestions"

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:

如前所述,禁用单词包装,XML属性android: scrollhorizontal ="true"不起作用。然而,奇怪的是,如果它是通过Java完成的,那么它就可以工作。以下是实现无词包装的必要代码:

mEditText.setHorizontallyScrolling(true);

mEditText.setHorizontallyScrolling(真正的);

#2


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 4.0+中,有时Textview中会出现红色下划线,因此我添加了属性……

android:inputType="textNoSuggestions" 

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

textNoSuggestions:指示IME不应该显示任何基于字典的词汇建议。

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

下面是我们可以在以下列表中定义的可能属性:android:inputType

Disabling Word-Wrap

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

记住,属性android: scroll水平="true"不工作,所以这是解决方案:

mEditText.setHorizontallyScrolling(true);

#3


9  

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

在Java类中,您可以添加到Edittext对象……

  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.

这将清除自动更正标志,并将在API 4中工作。

#4


7  

android:inputType="textMultiLine|textPhonetic"

removed all red underlines for me.

去掉所有红色下划线。

android:inputType="textMultiLine|textNoSuggestions"

produces compilation error.

产生编译错误。

I use Android API 1.6.

我使用Android API 1.6。

#5


5  

Disabling the spell checker for general text input via code:

通过代码禁用一般文本输入的拼写检查器:

mEditText.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);

#6


0  

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

删除android:inputType=",一切都应该很好。

#7


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.

要禁用行包装,您必须使用HorizontalScrollView将您的EditText包装(pun不打算),并将layout_width设置为match_parent。