Android Ice Cream Sandwich Edittext:禁用拼写检查和自动换行 [英] Android Ice Cream Sandwich Edittext: Disabling Spell Check and Word Wrap

查看:25
本文介绍了Android Ice Cream Sandwich Edittext:禁用拼写检查和自动换行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在运行 Android 4.0(冰淇淋三明治)的 Android 模拟器上进行测试时,我注意到 Edittext 做了一些非常奇怪的事情.

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

首先,它会在每个被识别为拼写错误"的单词下划线.红色的.如何禁用此功能?其次,虽然我在布局 XML 中指定了 android:scrollHorizo​​ntally=true" 自动换行:我该如何禁用它呢?这是 Edittext 的 Layout XML 代码:

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:


(来源:abstract-thoughts.com)

非常感谢!

推荐答案

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

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"

但是,我的 EditText 也需要是多行的,所以我在 EditText 的 XML 中添加了以下行:

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

android:inputType="textMultiLine|textNoSuggestions"

禁用自动换行
如前所述,XML 属性 android:scrollHorizo​​ntally="true" 不起作用.然而,奇怪的是,如果它是通过 Java 完成的,它确实可以工作.这是实现无自动换行的必要代码:

mEditText.setHorizo​​ntallyScrolling(true);

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

这篇关于Android Ice Cream Sandwich Edittext:禁用拼写检查和自动换行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆