Most visited

Recently visited

Added in API level 14

SuggestionSpan

public class SuggestionSpan
extends CharacterStyle implements ParcelableSpan

java.lang.Object
   ↳ android.text.style.CharacterStyle
     ↳ android.text.style.SuggestionSpan


持有此范围内的文本的建议候选人。 当在EditText中编辑这样的跨度时,双击包含在此跨度中的文本将显示一个弹出对话框,列出对该文本的建议替换。 然后,用户可以通过其中一个建议来替换原始文本。 这些跨度通常应该由输入法创建,以便为文本提供更正和替换。

也可以看看:

Summary

Constants

String ACTION_SUGGESTION_PICKED

int FLAG_AUTO_CORRECTION

如果自动更正即将应用于用户正在键入/撰写的单词/文本,请设置此标志。

int FLAG_EASY_CORRECT

设置此标志,如果建议应该很容易通过少量交互访问。

int FLAG_MISSPELLED

如果建议适用于拼写错误的单词/文本,请设置此标志。

int SUGGESTIONS_MAX_SIZE

String SUGGESTION_SPAN_PICKED_AFTER

String SUGGESTION_SPAN_PICKED_BEFORE

String SUGGESTION_SPAN_PICKED_HASHCODE

Inherited constants

From interface android.os.Parcelable

Fields

public static final Creator<SuggestionSpan> CREATOR

Public constructors

SuggestionSpan(Context context, String[] suggestions, int flags)
SuggestionSpan(Locale locale, String[] suggestions, int flags)
SuggestionSpan(Context context, Locale locale, String[] suggestions, int flags, Class<?> notificationTargetClass)
SuggestionSpan(Parcel src)

Public methods

int describeContents()

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

boolean equals(Object o)

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

int getFlags()
String getLocale()

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

Locale getLocaleObject()

Locale对象的形式返回建议的格式良好的BCP 47语言标记表示形式。

int getSpanTypeId()

返回此跨度类的特殊类型标识符。

String[] getSuggestions()
int hashCode()

返回对象的哈希码值。

void setFlags(int flags)
void updateDrawState(TextPaint tp)
void writeToParcel(Parcel dest, int flags)

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

Inherited methods

From class android.text.style.CharacterStyle
From class java.lang.Object
From interface android.text.ParcelableSpan
From interface android.os.Parcelable

Constants

ACTION_SUGGESTION_PICKED

Added in API level 14
String ACTION_SUGGESTION_PICKED

常量值:“android.text.style.SUGGESTION_PICKED”

FLAG_AUTO_CORRECTION

Added in API level 15
int FLAG_AUTO_CORRECTION

如果自动更正即将应用于用户正在键入/撰写的单词/文本,请设置此标志。 这种类型的建议呈现不同,表明正在进行自动更正。

常量值:4(0x00000004)

FLAG_EASY_CORRECT

Added in API level 14
int FLAG_EASY_CORRECT

设置此标志,如果建议应该很容易通过少量交互访问。 应该为用户可能使用的每个建议设置此标志。

常数值:1(0x00000001)

FLAG_MISSPELLED

Added in API level 14
int FLAG_MISSPELLED

如果建议适用于拼写错误的单词/文本,请设置此标志。 这种类型的建议呈现不同以突出显示错误。

常量值:2(0x00000002)

SUGGESTIONS_MAX_SIZE

Added in API level 14
int SUGGESTIONS_MAX_SIZE

常量值:5(0x00000005)

SUGGESTION_SPAN_PICKED_AFTER

Added in API level 14
String SUGGESTION_SPAN_PICKED_AFTER

常数值:“之后”

SUGGESTION_SPAN_PICKED_BEFORE

Added in API level 14
String SUGGESTION_SPAN_PICKED_BEFORE

常数值:“之前”

SUGGESTION_SPAN_PICKED_HASHCODE

Added in API level 14
String SUGGESTION_SPAN_PICKED_HASHCODE

常量值:“hashcode”

Fields

CREATOR

Added in API level 14
Creator<SuggestionSpan> CREATOR

Public constructors

SuggestionSpan

Added in API level 14
SuggestionSpan (Context context, 
                String[] suggestions, 
                int flags)

Parameters
context Context: Context for the application
suggestions String: Suggestions for the string under the span
flags int: Additional flags indicating how this span is handled in TextView

SuggestionSpan

Added in API level 14
SuggestionSpan (Locale locale, 
                String[] suggestions, 
                int flags)

Parameters
locale Locale: Locale of the suggestions
suggestions String: Suggestions for the string under the span
flags int: Additional flags indicating how this span is handled in TextView

SuggestionSpan

Added in API level 14
SuggestionSpan (Context context, 
                Locale locale, 
                String[] suggestions, 
                int flags, 
                Class<?> notificationTargetClass)

Parameters
context Context: Context for the application
locale Locale: locale Locale of the suggestions
suggestions String: Suggestions for the string under the span. Only the first up to SUGGESTIONS_MAX_SIZE will be considered. Null values not permitted.
flags int: Additional flags indicating how this span is handled in TextView
notificationTargetClass Class: if not null, this class will get notified when the user selects one of the suggestions.

SuggestionSpan

Added in API level 14
SuggestionSpan (Parcel src)

Parameters
src Parcel

Public methods

describeContents

Added in API level 14
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 14
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.

getFlags

Added in API level 14
int getFlags ()

Returns
int

getLocale

Added in API level 14
String getLocale ()

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

Returns
String the locale of the suggestions. An empty string is returned if no locale is specified.

getLocaleObject

Added in API level 24
Locale getLocaleObject ()

Locale对象的形式返回建议的格式良好的BCP 47语言标记表示形式。

警告 :返回的对象保证是一个格式良好的BCP 47语言标记表示。 例如,当此对象使用格式Locale对象(例如new Locale(" a ", " b c d ", " " )进行初始化时,此方法可以返回空白区域而不是返回格式错误的数据。

Returns
Locale the locale of the suggestions. null is returned if no locale is specified.

getSpanTypeId

Added in API level 14
int getSpanTypeId ()

返回此跨度类的特殊类型标识符。

Returns
int

getSuggestions

Added in API level 14
String[] getSuggestions ()

Returns
String[] an array of suggestion texts for this span

hashCode

Added in API level 14
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.

setFlags

Added in API level 14
void setFlags (int flags)

Parameters
flags int

updateDrawState

Added in API level 14
void updateDrawState (TextPaint tp)

Parameters
tp TextPaint

writeToParcel

Added in API level 14
void writeToParcel (Parcel dest, 
                int flags)

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

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

Hooray!