Android Ice Cream Sandwich Edittext:禁用拼写检查和自动换行

Android Ice Cream Sandwich Edittext: Disabling Spell Check and Word Wrap(Android Ice Cream Sandwich Edittext:禁用拼写检查和自动换行)
本文介绍了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:scrollHorizontally=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:scrollHorizontally="true" 不起作用.然而,奇怪的是,如果它是通过 Java 完成的,它确实可以工作.这是实现无自动换行的必要代码:

mEditText.setHorizontallyScrolling(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:禁用拼写检查和自动换行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Change the style of AlertDialog(更改 AlertDialog 的样式)
Pop up dialog in Android home screen(在 Android 主屏幕中弹出对话框)
How to display an existing ListFragment in a DialogFragment(如何在 DialogFragment 中显示现有的 ListFragment)
When to use Android PopupWindow vs Dialog(何时使用 Android PopupWindow vs Dialog)
Android: Close dialog window on touch(Android:触摸时关闭对话框窗口)
Android - Executing a custom listview in a custom dialog properly(Android - 在自定义对话框中正确执行自定义列表视图)