Most visited

Recently visited

Added in API level 11

InputMethodSubtype

public final class InputMethodSubtype
extends Object implements Parcelable

java.lang.Object
   ↳ android.view.inputmethod.InputMethodSubtype


该类用于指定输入法编辑器(IME)中包含的子类型的元信息。 子类型可以描述区域设置(例如en_US,fr_FR ...)和模式(例如语音,键盘...),并用于IME切换和设置。 输入法子类型允许系统直接调出指定IME的指定子类型。

它应该在<subtype>元素的输入方法的XML资源文件中定义,该元素驻留在<input-method>元素中。 有关更多信息,请参阅Creating an Input Method的指南。

也可以看看:

Summary

Nested classes

class InputMethodSubtype.InputMethodSubtypeBuilder

InputMethodSubtypeBuilder是InputMethodSubtype的构建器类。

XML attributes

android:icon The icon of the subtype. 
android:imeSubtypeExtraValue The extra value of the subtype. 
android:imeSubtypeLocale The locale of the subtype. 
android:imeSubtypeMode The mode of the subtype. 
android:isAsciiCapable Set to true if this subtype is ASCII capable. 
android:isAuxiliary Set true if the subtype is auxiliary. 
android:label The name of the subtype. 
android:languageTag The BCP-47 Language Tag of the subtype. 
android:overridesImplicitlyEnabledSubtype Set true when this subtype should be selected by default if no other subtypes are selected explicitly. 
android:subtypeId The unique id for the subtype. 

Inherited constants

From interface android.os.Parcelable

Fields

public static final Creator<InputMethodSubtype> CREATOR

Public constructors

InputMethodSubtype(int nameId, int iconId, String locale, String mode, String extraValue, boolean isAuxiliary, boolean overridesImplicitlyEnabledSubtype)

此构造函数在API级别19中已弃用。 InputMethodSubtype.InputMethodSubtypeBuilder改为使用InputMethodSubtype.InputMethodSubtypeBuilder 此构造函数的参数与“id”除外有相同的含义InputMethodSubtype(int, int, String, String, String, boolean, boolean, int)

InputMethodSubtype(int nameId, int iconId, String locale, String mode, String extraValue, boolean isAuxiliary, boolean overridesImplicitlyEnabledSubtype, int id)

此构造函数在API级别19中已弃用。 InputMethodSubtype.InputMethodSubtypeBuilder改为使用InputMethodSubtype.InputMethodSubtypeBuilder “isAsciiCapable”在这个构造函数中是“false”。

Public methods

boolean containsExtraValueKey(String key)

子类型中ExtraValue的字符串应该定义如下:例如:key0,key1 = value1,key2,key3,key4 = value4

int describeContents()

描述此Parcelable实例的封送表示中包含的特殊对象的种类。

boolean equals(Object o)

指示其他某个对象是否“等于”这一个。

CharSequence getDisplayName(Context context, String packageName, ApplicationInfo appInfo)

返回此子类型的显示名称。

String getExtraValue()
String getExtraValueOf(String key)

子类型中ExtraValue的字符串应该定义如下:例如:key0,key1 = value1,key2,key3,key4 = value4

int getIconResId()
String getLanguageTag()
String getLocale()

此方法在API级别24中已弃用。请改用getLanguageTag()

String getMode()
int getNameResId()
int hashCode()

返回对象的哈希码值。

boolean isAsciiCapable()
boolean isAuxiliary()
boolean overridesImplicitlyEnabledSubtype()
void writeToParcel(Parcel dest, int parcelableFlags)

将此对象平铺到一个包裹中。

Inherited methods

From class java.lang.Object
From interface android.os.Parcelable

XML attributes

android:icon

子类型的图标。

必须是另一个资源的引用,其形式为“ @[+][package:]type:name ”,或者其形式为“一个主题属性 ?[package:][type:]name ”。

这对应于全局属性资源符号 icon

android:imeSubtypeExtraValue

子类型的额外值。 该字符串可以是任何字符串,并在框架使用子类型调用IME时传递给IME。

必须是字符串值,使用'\\;' 转义字符如'\\ n'或'\\ uxxxx'作为unicode字符。

这也可以是对包含此类型值的资源(形式为“ @[package:]type:name ”)或主题属性(形式为“ ?[package:][type:]name ”)的 ?[package:][type:]name

这对应于全局属性资源符号 imeSubtypeExtraValue

android:imeSubtypeLocale

子类型的区域设置。 该字符串应该是区域设置(例如en_US,fr_FR ...),并且在框架使用子类型调用IME时将传递给IME。 这也被框架用来了解IME支持的语言环境。

必须是字符串值,使用'\\;' 转义字符如'\\ n'或'\\ uxxxx'作为unicode字符。

这也可能是对包含此类型值的资源(形式为“ @[package:]type:name ”)或主题属性(形式为“ ?[package:][type:]name ”)的 ?[package:][type:]name

这对应于全局属性资源符号 imeSubtypeLocale

android:imeSubtypeMode

子类型的模式。 该字符串可以是一个模式(例如语音,键盘......),并且当框架使用子类型调用IME时,该字符串将传递给IME。 getLocale()返回此属性中指定的值。

必须是字符串值,使用'\\;' 转义字符如'\\ n'或'\\ uxxxx'作为unicode字符。

这也可能是对包含此类型值的资源(形式为“ @[package:]type:name ”)或主题属性(形式为“ ?[package:][type:]name ”)的 ?[package:][type:]name

这对应于全局属性资源符号 imeSubtypeMode

android:isAsciiCapable

如果此子类型为ASCII能力,则设置为true。 如果子类型是ASCII能力的,它应该保证用户可以输入这个子类型的ASCII字符。 这很重要,因为许多密码字段只允许使用ASCII字符。

必须是布尔值,可以是“ true ”或“ false ”。

这也可能是对包含此类型值的资源(形式为“ @[package:]type:name ”)或主题属性(形式为“ ?[package:][type:]name ”)的 ?[package:][type:]name

这对应于全局属性资源符号 isAsciiCapable

android:isAuxiliary

如果子类型是辅助,则设置为true。 辅助子类型不会显示在设置应用程序的输入法选择列表中。 InputMethodManager#switchToLastInputMethod将在选择目标子类型时忽略辅助子类型。

必须是布尔值,可以是“ true ”或“ false ”。

这也可能是对包含此类型值的资源(形式为“ @[package:]type:name ”)或主题属性(形式为“ ?[package:][type:]name ”)的 ?[package:][type:]name

这对应于全局属性资源符号 isAuxiliary

android:label

子类型的名称。

可能是对另一个资源的引用,形式为“ @[+][package:]type:name ”,也可能是对“ ?[package:][type:]name ”形式的主题属性。

可能是一个字符串值,使用'\\;' 转义字符如'\\ n'或'\\ uxxxx'作为unicode字符。

这对应于全局属性资源符号 label

android:languageTag

子类型的BCP-47语言标签。 这取代了InputMethod_Subtype_imeSubtypeLocale

必须是字符串值,使用'\\;' 转义字符如'\\ n'或'\\ uxxxx'作为unicode字符。

这也可能是对包含此类型值的资源(形式为“ @[package:]type:name ”)或主题属性(形式为“ ?[package:][type:]name ”)的 ?[package:][type:]name

这对应于全局属性资源符号 languageTag

android:overridesImplicitlyEnabledSubtype

如果没有明确选择其他子类型,则应该在默认情况下选择此子类型时设置为true。 请注意,此参数为true的子类型不会显示在子类型列表中。

必须是布尔值,可以是“ true ”或“ false ”。

这也可能是对包含此类型值的资源(形式为“ @[package:]type:name ”)或主题属性(形式为“ ?[package:][type:]name ”)的 ?[package:][type:]name

这对应于全局属性资源符号 overridesImplicitlyEnabledSubtype

android:subtypeId

子类型的唯一ID。 输入法框架通过ID跟踪启用的子类型。 当IME软件包升级时,即使其他属性不同,启用的ID也会保持启用状态。 如果ID未指定(通过调用其他构造函数或0),将使用Arrays.hashCode(new Object [] {locale,mode,extraValue,isAuxiliary,overridesImplicitlyEnabledSubtype})。

必须是整数值,例如“ 100 ”。

这也可能是对包含此类型值的资源(形式为“ @[package:]type:name ”)或主题属性(形式为“ ?[package:][type:]name ”)的 ?[package:][type:]name

这对应于全局属性资源符号 subtypeId

Fields

CREATOR

Added in API level 11
Creator<InputMethodSubtype> CREATOR

Public constructors

InputMethodSubtype

Added in API level 14
InputMethodSubtype (int nameId, 
                int iconId, 
                String locale, 
                String mode, 
                String extraValue, 
                boolean isAuxiliary, 
                boolean overridesImplicitlyEnabledSubtype)

此构造函数在API级别19中已被弃用。
改为使用InputMethodSubtype.InputMethodSubtypeBuilder 此构造函数的参数与“id”除外有相同的含义InputMethodSubtype(int, int, String, String, String, boolean, boolean, int)

没有指定子类型ID的构造函数。

Parameters
nameId int
iconId int
locale String
mode String
extraValue String
isAuxiliary boolean
overridesImplicitlyEnabledSubtype boolean

InputMethodSubtype

Added in API level 17
InputMethodSubtype (int nameId, 
                int iconId, 
                String locale, 
                String mode, 
                String extraValue, 
                boolean isAuxiliary, 
                boolean overridesImplicitlyEnabledSubtype, 
                int id)

此构造函数在API级别19中已被弃用。
改为使用InputMethodSubtype.InputMethodSubtypeBuilder “isAsciiCapable”在这个构造函数中是“false”。

构造函数。

Parameters
nameId int: Resource ID of the subtype name string. The string resource may have exactly one %s in it. If there is, the %s part will be replaced with the locale's display name by the formatter. Please refer to getDisplayName(Context, String, ApplicationInfo) for details.
iconId int: Resource ID of the subtype icon drawable.
locale String: The locale supported by the subtype
mode String: The mode supported by the subtype
extraValue String: The extra value of the subtype. This string is free-form, but the API supplies tools to deal with a key-value comma-separated list; see containsExtraValueKey(String) and getExtraValueOf(String).
isAuxiliary boolean: true when this subtype is auxiliary, false otherwise. An auxiliary subtype will not be shown in the list of enabled IMEs for choosing the current IME in the Settings even when this subtype is enabled. Please note that this subtype will still be shown in the list of IMEs in the IME switcher to allow the user to tentatively switch to this subtype while an IME is shown. The framework will never switch the current IME to this subtype by switchToLastInputMethod(IBinder). The intent of having this flag is to allow for IMEs that are invoked in a one-shot way as auxiliary input mode, and return to the previous IME once it is finished (e.g. voice input).
overridesImplicitlyEnabledSubtype boolean: true when this subtype should be enabled by default if no other subtypes in the IME are enabled explicitly. Note that a subtype with this parameter being true will not be shown in the list of subtypes in each IME's subtype enabler. Having an "automatic" subtype is an example use of this flag.
id int: The unique ID for the subtype. The input method framework keeps track of enabled subtypes by ID. When the IME package gets upgraded, enabled IDs will stay enabled even if other attributes are different. If the ID is unspecified or 0, Arrays.hashCode(new Object[] {locale, mode, extraValue, isAuxiliary, overridesImplicitlyEnabledSubtype, isAsciiCapable}) will be used instead.

Public methods

containsExtraValueKey

Added in API level 12
boolean containsExtraValueKey (String key)

子类型中ExtraValue的字符串应该定义如下:例如:key0,key1 = value1,key2,key3,key4 = value4

Parameters
key String: The key of extra value
Returns
boolean The subtype contains specified the extra value

describeContents

Added in API level 11
int describeContents ()

描述此Parcelable实例的封送表示中包含的特殊对象的种类。 例如,如果对象在writeToParcel(Parcel, int)的输出中包含writeToParcel(Parcel, int) ,则此方法的返回值必须包含CONTENTS_FILE_DESCRIPTOR位。

Returns
int a bitmask indicating the set of special object types marshaled by this Parcelable object instance.

equals

Added in API level 11
boolean equals (Object o)

指示其他某个对象是否“等于”这一个。

equals方法在非空对象引用上实现等价关系:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

Objectequals方法实现了对象上最可能的等价关系; 也就是说,对于任何非空参考值xy ,当且仅当xy引用同一对象( x == y的值为true )时,此方法返回true

请注意,无论何时重写此方法,通常都需要重写 hashCode方法,以便维护 hashCode方法的一般合同,该方法声明等同对象必须具有相同的哈希代码。

Parameters
o Object: the reference object with which to compare.
Returns
boolean true if this object is the same as the obj argument; false otherwise.

getDisplayName

Added in API level 14
CharSequence getDisplayName (Context context, 
                String packageName, 
                ApplicationInfo appInfo)

返回此子类型的显示名称。

如果指定了subtypeNameResId (!= 0),则将返回从该资源生成的文本。 标签的本地化字符串资源应该大写以包含在UI列表中。 字符串资源最多可以包含一个%s 如果存在,则%s将替换为用户语言环境中的子类型区域设置的显示名称。

如果未指定 subtypeNameResId (== 0),则框架返回用户的语言环境中用于UI列表的大写的子类型语言环境的显示名称。

Parameters
context Context: Context will be used for getting Locale and PackageManager.
packageName String: The package name of the input method.
appInfo ApplicationInfo: The ApplicationInfo of the input method.
Returns
CharSequence a display name for this subtype.

getExtraValue

Added in API level 11
String getExtraValue ()

Returns
String The extra value of the subtype.

getExtraValueOf

Added in API level 12
String getExtraValueOf (String key)

子类型中ExtraValue的字符串应该定义如下:例如:key0,key1 = value1,key2,key3,key4 = value4

Parameters
key String: The key of extra value
Returns
String The value of the specified key

getIconResId

Added in API level 11
int getIconResId ()

Returns
int Resource ID of the subtype icon drawable.

getLanguageTag

Added in API level 24
String getLanguageTag ()

Returns
String the BCP-47 Language Tag of the subtype. Returns an empty string when no Language Tag is specified.

也可以看看:

getLocale

Added in API level 11
String getLocale ()

此方法在API级别24中已弃用。
改为使用getLanguageTag()

Returns
String The locale of the subtype. This method returns the "locale" string parameter passed to the constructor.

getMode

Added in API level 11
String getMode ()

Returns
String The mode of the subtype.

getNameResId

Added in API level 11
int getNameResId ()

Returns
int Resource ID of the subtype name string.

hashCode

Added in API level 11
int hashCode ()

返回对象的哈希码值。 为了散列表的好处而支持此方法,例如由HashMap提供的HashMap

hashCode的总合同是:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals(Object) method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals(java.lang.Object) method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.

尽可能合理实用,类Object定义的hashCode方法确实为不同的对象返回不同的整数。 (这通常通过将对象的内部地址转换为整数来实现,但Java TM编程语言不需要此实现技术。)

Returns
int a hash code value for this object.

isAsciiCapable

Added in API level 19
boolean isAsciiCapable ()

Returns
boolean true if this subtype is Ascii capable, false otherwise. If the subtype is ASCII capable, it should guarantee that the user can input ASCII characters with this subtype. This is important because many password fields only allow ASCII-characters.

isAuxiliary

Added in API level 14
boolean isAuxiliary ()

Returns
boolean true if this subtype is auxiliary, false otherwise. An auxiliary subtype will not be shown in the list of enabled IMEs for choosing the current IME in the Settings even when this subtype is enabled. Please note that this subtype will still be shown in the list of IMEs in the IME switcher to allow the user to tentatively switch to this subtype while an IME is shown. The framework will never switch the current IME to this subtype by switchToLastInputMethod(IBinder). The intent of having this flag is to allow for IMEs that are invoked in a one-shot way as auxiliary input mode, and return to the previous IME once it is finished (e.g. voice input).

overridesImplicitlyEnabledSubtype

Added in API level 14
boolean overridesImplicitlyEnabledSubtype ()

Returns
boolean true when this subtype will be enabled by default if no other subtypes in the IME are enabled explicitly, false otherwise. Note that a subtype with this method returning true will not be shown in the list of subtypes in each IME's subtype enabler. Having an "automatic" subtype is an example use of this flag.

writeToParcel

Added in API level 11
void writeToParcel (Parcel dest, 
                int parcelableFlags)

将此对象平铺到一个包裹中。

Parameters
dest Parcel: The Parcel in which the object should be written.
parcelableFlags int: Additional flags about how the object should be written. May be 0 or PARCELABLE_WRITE_RETURN_VALUE.

Hooray!