各有什么InputType不变的语义? [英] What are the semantics of each InputType constant?

查看:377
本文介绍了各有什么InputType不变的语义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您可以设置的TextView inputType 的值从 InputType 1 暗示的键入的文本应该是一个人的名字,电话号码,和C。即使输入法不尊重这个提示,在的TextView 使用的KeyListener 和/或 TransformationMethod 来保证只有相关的字符可​​以进入,或者有像掩盖密码的效果。即使是标志不仅仅是提示:他们可以修改的TextView 显著(最明显的例子是 EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE )。

You can set a TextView's inputType to one of the values from InputType to hint that the typed-in text should be a person's name, phone number, &c. Even if the input method doesn't respect this hint, the TextView uses a KeyListener and/or TransformationMethod to ensure that only relevant characters can be entered, or to have effects like masking the password. Even the flags are more than just hints: they can change the behaviour of the TextView significantly (the most obvious example being EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE).

谷歌的文档是很模糊的每个 inputType 的实际效果。在每种情况下实际上是允许哪些字符?这是如何通过语言环境各不相同,如果在所有?即使是没有的文件的答案,这是责任版本之间改变,我还是想知道预期的行为。

Google's documentation is very vague about the actual effect of each inputType. What characters are actually permitted in each case? How does this vary by locale, if at all? Even if there is no documented answer, and it's liable to change between versions, I'd still like to know the expected behaviour.

推荐答案

您可以发现这一点通过检查的 *的KeyListener 类,但当然,这可能会在源在不同的版本或由制造商或运营商定制被改变。下面是基于AOSP 4.3源。这些仅是,每个类型具有对机器人本身的影响:输入方法也使用类型作为提示来更好predict什么用户可能键入。例如,虽然 TYPE_TEXT_VARIATION_PERSON_NAME 仅具有禁用拼写检查的作用,在IM可能对这种类型的由自动完成从普通名称词典,而不是从一个语言响应字典。

You can find this out by inspecting the source of the *KeyListener classes, though of course this may be changed in different versions or by manufacturer or carrier customizations. The below is based on the AOSP 4.3 source. These are only the effects that each type has on Android itself: input methods also use the types as hints to better predict what the user is likely to type. For example, although TYPE_TEXT_VARIATION_PERSON_NAME only has the effect of disabling spell-check, the IM might respond to this type by auto-completing from a dictionary of common names instead of from a language dictionary.

要尝试输入类型和输入法的选择,我砍死了一个快速的应用程序,让您从一个图形用户界面列表中选择它们,这样你就不必编辑XML布局和重建一个应用程序来做到这一点。如果您想了解更多信息,或检查它们与给定的IM应用程序的交互方式,的下载 IM证明免费从谷歌播放

To experiment with input types and IME options, I hacked up a quick app that lets you select them from a list in a GUI, so you don't have to edit an XML layout and rebuild an app to do it. If you want to find out more, or check how they interact with a given IM app, download IM prove free from Google Play.

这一块其实记载:

这应该是PTED意味着该目标输入连接不丰富跨$ P $,它不能处理和显示之类的候选文字和获取当前的文本,所以该输入法需要在一个有限的运行生成的关键事件的模式,如果它支持它。需要注意的是某些输入方法可能不支持它,例如基于语音的输入法将有可能不能够生成即使该标志置的重要事件。

This should be interpreted to mean that the target input connection is not rich, it can not process and show things like candidate text nor retrieve the current text, so the input method will need to run in a limited "generate key events" mode, if it supports it. Note that some input methods may not support it, for example a voice-based input method will likely not be able to generate key events even if this flag is set.

这使得它听起来像它的情况下,你不编辑文本,但pressing对IM的一个关键,将直接做一些动作。但事实上它完全隐藏的IM。但从应用程序的角度来看,你几乎永远不希望这样的:设置,如果你只想要一个硬件键盘可以输入文本

This makes it sounds like it's for cases where you're not editing text, but pressing a key on the IM will do some action directly. But in fact it hides the IM completely. From the app's point of view, you almost never want this: set it if you only want a hardware keyboard to be able to enter text.

从的角度IM的时候,你会得到这种类型的传递给 onStartInput 很多时候,通常Android是要隐藏的IM,因为不同的活动来了到前台。你要应对这种输入类型要快。可能有两个原因,为什么是这样工作的,但有人参与了设计,就必须确认原因: -

From the IM's point of view, you'll get this type passed to onStartInput a lot, usually when Android is about to hide the IM because a different activity is coming to the foreground. You want responding to this input type to be fast. There could be two reasons why it works this way, but someone involved with the design would have to confirm why:-

  1. 这可能是让IM知道编辑是在窗口完全完成(不同于 onFinishInput ,这仅仅意味着IM被隐藏),所以它可以释放内存用于词典等的编辑,直到重新启动。

  1. It could be to let the IM know that editing is completely finished in that window (unlike onFinishInput, which merely means the IM is being hidden), so it can free memory used for dictionaries and the like until editing restarts.

这可能是什么让一个硬件键盘使用箭头键滚动,菜单快捷键等,即使没有文字输入的是正在发生的部分。

It could be part of what allows a hardware keyboard to use arrow keys for scrolling, menu accelerator keys, and so on, even when no text input is taking place.

TYPE_CLASS_NUMBER 为您提供了数字0-9。此外,加入 TYPE_NUMBER_FLAG_SIGNED 让你有 + - ,但只是作为第一个字符。添加 TYPE_NUMBER_FLAG_DECIMAL 让你有在任何位置,但只有一次。您的可以的已经有符号和小数。据我所知,这的不是的本地化,所以允许的字符是相同的,即使语言环境,其中是千位分隔符和是小数点,或者区域设置不同的字符数。

Classes

Numeric types

TYPE_CLASS_NUMBER gives you the digits 0-9. In addition, adding TYPE_NUMBER_FLAG_SIGNED lets you have + or -, but only as the first character. Adding TYPE_NUMBER_FLAG_DECIMAL lets you have . in any position, but only once. You can have both signed and decimal. As far as I can tell, this isn't localized, so the allowed characters are the same even for locales where . is the thousands separator and , is the decimal point, or for locales with different number characters.

TYPE_CLASS_PHONE 让你有数字0-9,以及任何的#* + - ()/ N; 和空间。您可以按任意顺序和任意次数的字符:有没有格式化检查

TYPE_CLASS_PHONE lets you have the digits 0-9, as well as any of #*+-(),/N.; and space. You can have those characters in any order and any number of times: there's no formatting check.

TYPE_CLASS_DATETIME | TYPE_DATETIME_VARIATION_DATE 让你有数字0-9,以及任何的 / - 。此外,还有用于格式化没有额外的检查,这样你就可以按任意顺序。

TYPE_CLASS_DATETIME | TYPE_DATETIME_VARIATION_DATE lets you have the digits 0-9 as well as any of /-.. Again, there's no extra check for formatting, so you can have them in any order.

TYPE_CLASS_DATETIME | TYPE_DATETIME_VARIATION_TIME 让你有数字0-9,以及任何安培的(写AM或PM,但您可以使用按任意顺序和位置)。稍微反常,不能有空格或。对于下午3点或下午2点甚至是2.30。再次,它似乎并没有进行本地化。

TYPE_CLASS_DATETIME | TYPE_DATETIME_VARIATION_TIME lets you have the digits 0-9 as well as : and any of amp (for writing "am" or "pm", but you can use them in any order and position). Slightly perversely, you can't have space or . for "3 pm" or "2 p.m." or even "2.30". Again, it doesn't seem to be localized.

TYPE_CLASS_DATETIME | TYPE_DATETIME_VARIATION_NORMAL 让你0-9以及:/ - ,空间和安培 。这明显不包括即使它允许一个日期。

TYPE_CLASS_DATETIME | TYPE_DATETIME_VARIATION_NORMAL gets you 0-9 as well as :/-, space, and amp. This notably doesn't include . even though it's allowed in a date.

根据上述意见,我不能说我建议你使用任何上述类别。他们都似乎有重大的缺席和prevent定位。以上是唯一的班,字符限制。

Based on the above observations, I can't say I'd recommend using any of the above classes. They all seem to have major absences and prevent localization. The above are the only classes with character restrictions.

TYPE_CLASS_NUMBER | TYPE_NUMBER_VARIATION_PASSWORD 确实如你所期望:它使用了 TransformationMethod 来掩盖键入的字符

TYPE_CLASS_NUMBER | TYPE_NUMBER_VARIATION_PASSWORD does as you'd expect: it uses a TransformationMethod to obscure the typed characters.

TYPE_CLASS_TEXT ,设置 TYPE_TEXT_VARIATION_EMAIL_ADDRESS TYPE_TEXT_VARIATION_EMAIL_SUBJECT 品牌的回车键将焦点移动到下一个字段preSS而不是插入一个新行。

In TYPE_CLASS_TEXT, setting TYPE_TEXT_VARIATION_EMAIL_ADDRESS or TYPE_TEXT_VARIATION_EMAIL_SUBJECT makes a press of the enter key move focus to the next field instead of inserting a newline.

TYPE_TEXT_VARIATION_FILTER 将prevent输入法将全屏幕(摘录)模式。

TYPE_TEXT_VARIATION_FILTER will prevent the input method going to full-screen (extract) mode.

TYPE_TEXT_VARIATION_PASSWORD 有明显的效果:它使用了 TransformationMethod 模糊输入的字符。 TYPE_TEXT_VARIATION_VISIBLE_PASSWORD 仍然使用 TransformationMethod 来prevent的文字被复制

TYPE_TEXT_VARIATION_PASSWORD has the obvious effect: it uses a TransformationMethod to obscure the typed characters. TYPE_TEXT_VARIATION_VISIBLE_PASSWORD still uses the TransformationMethod to prevent the text being copied

下面所有的文字变化让拼写检查,如果 TYPE_TEXT_FLAG_NO_SUGGESTIONS 未设置。也就是说,使用类不是 TYPE_CLASS_TEXT 或变种,是的没有的在此列表中具有相同的效果设置 TYPE_TEXT_FLAG_NO_SUGGESTIONS (后述)。

All of the following text variations allow spell-checking if TYPE_TEXT_FLAG_NO_SUGGESTIONS is not set. That is, using an class that is not TYPE_CLASS_TEXT or a variation that is not in this list has the same effect as setting TYPE_TEXT_FLAG_NO_SUGGESTIONS (which is described later).

  • TYPE_TEXT_VARIATION_NORMAL
  • TYPE_TEXT_VARIATION_EMAIL_SUBJECT
  • TYPE_TEXT_VARIATION_LONG_MESSAGE
  • TYPE_TEXT_VARIATION_SHORT_MESSAGE
  • TYPE_TEXT_VARIATION_WEB_EDIT_TEXT
  • TYPE_TEXT_VARIATION_NORMAL
  • TYPE_TEXT_VARIATION_EMAIL_SUBJECT
  • TYPE_TEXT_VARIATION_LONG_MESSAGE
  • TYPE_TEXT_VARIATION_SHORT_MESSAGE
  • TYPE_TEXT_VARIATION_WEB_EDIT_TEXT

在presence与否 InputType.TYPE_TEXT_FLAG_MULTI_LINE 的具有无明显的副作用。如果类型类的没有 TYPE_CLASS_TEXT ,它始终是,如果旗是的没有的设置,而的TextView 进入单行模式。设置 MAXLINES 1只影响显示文本的方式:它的不是启动单行模式。

The presence or absence of InputType.TYPE_TEXT_FLAG_MULTI_LINE has non-obvious side-effects. If the type class is not TYPE_CLASS_TEXT, it is always as if the flag were not set, and the TextView goes into single-line mode. Setting lines or maxLines to 1 only affects the way the text is displayed: it does not start single-line mode.

在单行模式: -

  • 的ellipsize选项默认为结束
  • pressing进入执行编辑器操作或将焦点移动到下一个字段(就像电子邮件地址或主题,以上);否则,它插入一个新行
  • pressing Tab将焦点移到下一个字段,只有当 TYPE_TEXT_FLAG_IME_MULTI_LINE 未设置;否则插入一个制表符
  • imeOptions 可以包括编辑动作,更换输入软键盘上的按键;在多行模式,的TextView IME_FLAG_NO_ENTER_ACTION 添加到 imeOptions
  • MAXLINES 将自动设置为1
  • 添加一个新行的字段(例如,使用的setText )没有任何作用,并回车替换为一个零宽度的空间(U + FEFF)
  • the ellipsize option defaults to end
  • pressing enter performs the "editor action" or moves focus to the next field (just as for email addresses or subjects, above); otherwise, it inserts a newline
  • pressing tab moves focus to the next field, only if TYPE_TEXT_FLAG_IME_MULTI_LINE is not set; otherwise it inserts a tab character
  • the imeOptions can include an "editor action" to replace the enter key on a soft keyboard; in multi-line mode, TextView will add IME_FLAG_NO_ENTER_ACTION to the imeOptions
  • maxLines is automatically set to 1
  • adding a newline to the field (e.g. using setText) has no effect, and a carriage return is replaced with a zero-width space (U+FEFF)

TYPE_TEXT_FLAG_CAP _ * 使用 TextUtils.getCapsMode 来决定是否要利用每一个字符。该规则是一个小巴洛克式的,而且的没有的语言环境敏感。 AFAICT,这才会生效,如果相应的设置在默认的键盘功能。

TYPE_TEXT_FLAG_CAP_* use TextUtils.getCapsMode to decide whether to capitalize each character. The rules are a little baroque and are not locale-sensitive. AFAICT, this only takes effect if the corresponding setting is enabled in the default keyboard.

TYPE_TEXT_FLAG_AUTO_CORRECT 设置,空格,制表符,换行符,任何统一code结束标点字,或任何的,. !?将触发自动校正的preceding字(在这种情况下,这是对统一code字母和撇号最长的顺序)。如果整个字没有一个改正的,将继续重试较短的子序列的修正来自于一个固定的系统资源 com.android.internal.R.xml.autotext ,并独立于任何配置的法术-checker。

When TYPE_TEXT_FLAG_AUTO_CORRECT is set, space, tab, newline, any Unicode "end punctuation" character, or any of ,.!?" will trigger auto-correction of the preceding word (in this context, that's the longest sequence of Unicode letters and apostrophes). If the whole word doesn't have a correction, it continues to retry with shorter subsequences. The corrections come from a fixed system resource com.android.internal.R.xml.autotext and are separate from any configured spell-checker.

TYPE_TEXT_FLAG_NO_SUGGESTIONS (或前面列出的文字版本)停止文本存在拼写检查。这prevents正在显示拼写检查建议列表,并且停止拼写错误的单词被高亮显示。输入法依然可以提供补全,如果它选择。

TYPE_TEXT_FLAG_NO_SUGGESTIONS (or the text variations listed earlier) stops the text being spell-checked. This prevents the spell-check suggestions list being shown, and also stops misspelled words being highlighted. The input method can still provide completions if it chooses.

长攻一个的TextView 通常选择抽头词,但如果输入类型为以下之一,它选择所有的文本,而不是: -

Long-tapping a TextView usually selects the tapped word, but if the input type is one of the following, it selects all of the text instead:-

  • TYPE_CLASS_NUMBER
  • TYPE_CLASS_PHONE
  • TYPE_CLASS_DATETIME (任何变化)
  • TYPE_TEXT_VARIATION_URI
  • TYPE_TEXT_VARIATION_EMAIL_ADDRESS
  • TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS
  • TYPE_TEXT_VARIATION_FILTER
  • TYPE_CLASS_NUMBER
  • TYPE_CLASS_PHONE
  • TYPE_CLASS_DATETIME (any variation)
  • TYPE_TEXT_VARIATION_URI
  • TYPE_TEXT_VARIATION_EMAIL_ADDRESS
  • TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS
  • TYPE_TEXT_VARIATION_FILTER

这篇关于各有什么InputType不变的语义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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