Most visited

Recently visited

Added in API level 1

Linkify

public class Linkify
extends Object

java.lang.Object
   ↳ android.text.util.Linkify


Linkify获取一段文本和一个正则表达式,并将文本中的所有正则表达式匹配转换为可点击的链接。 这对于匹配诸如电子邮件地址,网址等等的东西并使其可操作性特别有用。 与需要匹配的模式一样,URL方案前缀也是必需的。 任何不是以提供的方案开始的模式匹配都会在创建可点击的URL时将该模式预先添加到匹配的文本中。 例如,如果您匹配的是网址,您可以提供方案http:// 如果模式匹配没有URL方案前缀的example.com,则在创建可点击的URL链接时,会提供附带的方案以创建http://example.com

Summary

Nested classes

interface Linkify.MatchFilter

MatchFilter使客户端代码可以更好地控制允许匹配的内容,并成为一个链接,而不是。

interface Linkify.TransformFilter

TransformFilter使客户端代码可以更好地控制如何将匹配的模式表示为URL。

Constants

int ALL

位掩码指示所有可用模式应该在采用选项掩码的方法中匹配

int EMAIL_ADDRESSES

位字段指示在采用选项掩码的方法中应该匹配电子邮件地址

int MAP_ADDRESSES

位域指示在采用选项掩码的方法中应该匹配街道地址。

int PHONE_NUMBERS

位字段指示在采用选项掩码的方法中应该匹配电话号码

int WEB_URLS

位字段指示在采用选项掩码的方法中应匹配网址

Fields

public static final Linkify.MatchFilter sPhoneNumberMatchFilter

过滤掉没有足够数字的URL匹配作为电话号码。

public static final Linkify.TransformFilter sPhoneNumberTransformFilter

将匹配的电话号码文本转换为适合在tel:URL中使用的内容。

public static final Linkify.MatchFilter sUrlMatchFilter

过滤出符号(@)后发生的网址匹配。

Public constructors

Linkify()

Public methods

static final void addLinks(TextView text, Pattern pattern, String scheme, Linkify.MatchFilter matchFilter, Linkify.TransformFilter transformFilter)

将正则表达式应用于TextView的文本,将匹配转换为链接。

static final void addLinks(TextView text, Pattern pattern, String defaultScheme, String[] schemes, Linkify.MatchFilter matchFilter, Linkify.TransformFilter transformFilter)

将正则表达式应用于TextView的文本,将匹配转换为链接。

static final boolean addLinks(Spannable spannable, Pattern pattern, String defaultScheme, String[] schemes, Linkify.MatchFilter matchFilter, Linkify.TransformFilter transformFilter)

将正则表达式应用于Spannable,将匹配转换为链接。

static final boolean addLinks(Spannable text, Pattern pattern, String scheme)

将正则表达式应用于Spannable,将匹配转换为链接。

static final boolean addLinks(Spannable text, int mask)

扫描提供的Spannable的文本,并将掩码中指定的所有链接类型转换为可点击的链接。

static final void addLinks(TextView text, Pattern pattern, String scheme)

将正则表达式应用于TextView的文本,将匹配转换为链接。

static final boolean addLinks(Spannable spannable, Pattern pattern, String scheme, Linkify.MatchFilter matchFilter, Linkify.TransformFilter transformFilter)

将正则表达式应用于Spannable,将匹配转换为链接。

static final boolean addLinks(TextView text, int mask)

扫描提供的TextView的文本,并将掩码中指定的所有链接类型转换为可点击的链接。

Inherited methods

From class java.lang.Object

Constants

ALL

Added in API level 1
int ALL

位掩码指示所有可用模式应该在采用选项掩码的方法中匹配

常量值:15(0x0000000f)

EMAIL_ADDRESSES

Added in API level 1
int EMAIL_ADDRESSES

位字段指示在采用选项掩码的方法中应该匹配电子邮件地址

常量值:2(0x00000002)

MAP_ADDRESSES

Added in API level 1
int MAP_ADDRESSES

位域指示在采用选项掩码的方法中应该匹配街道地址。 请注意,这里使用了findAddress()方法WebView查找地址,里面有各种限制。

常量值:8(0x00000008)

PHONE_NUMBERS

Added in API level 1
int PHONE_NUMBERS

位字段指示在采用选项掩码的方法中应该匹配电话号码

常量值:4(0x00000004)

WEB_URLS

Added in API level 1
int WEB_URLS

位字段指示在采用选项掩码的方法中应匹配网址

常数值:1(0x00000001)

Fields

sPhoneNumberMatchFilter

Added in API level 1
Linkify.MatchFilter sPhoneNumberMatchFilter

过滤掉没有足够数字的URL匹配作为电话号码。

sPhoneNumberTransformFilter

Added in API level 1
Linkify.TransformFilter sPhoneNumberTransformFilter

将匹配的电话号码文本转换为适合在tel:URL中使用的内容。 它通过移除除数字和加号之外的所有内容来完成此操作。 例如:'+1(919)555-1212'变成'+19195551212'

sUrlMatchFilter

Added in API level 1
Linkify.MatchFilter sUrlMatchFilter

过滤出符号(@)后发生的网址匹配。 这是为了防止将电子邮件地址中的域名转换为网络链接。

Public constructors

Linkify

Added in API level 1
Linkify ()

Public methods

addLinks

Added in API level 1
void addLinks (TextView text, 
                Pattern pattern, 
                String scheme, 
                Linkify.MatchFilter matchFilter, 
                Linkify.TransformFilter transformFilter)

将正则表达式应用于TextView的文本,将匹配转换为链接。 如果找到链接,则将UrlSpans应用于链接文本匹配区域,并将文本的移动方法更改为LinkMovementMethod。

Parameters
text TextView: TextView whose text is to be marked-up with links
pattern Pattern: Regex pattern to be used for finding links
scheme String: URL scheme string (eg http://) to be prepended to the links that do not start with this scheme.
matchFilter Linkify.MatchFilter: The filter that is used to allow the client code additional control over which pattern matches are to be converted into links.
transformFilter Linkify.TransformFilter

addLinks

Added in API level 24
void addLinks (TextView text, 
                Pattern pattern, 
                String defaultScheme, 
                String[] schemes, 
                Linkify.MatchFilter matchFilter, 
                Linkify.TransformFilter transformFilter)

将正则表达式应用于TextView的文本,将匹配转换为链接。 如果找到链接,则将UrlSpans应用于链接文本匹配区域,并将文本的移动方法更改为LinkMovementMethod。

Parameters
text TextView: TextView whose text is to be marked-up with links.
pattern Pattern: Regex pattern to be used for finding links.
defaultScheme String: The default scheme to be prepended to links if the link does not start with one of the schemes given.
schemes String: Array of schemes (eg http://) to check if the link found contains a scheme. Passing a null or empty value means prepend defaultScheme to all links.
matchFilter Linkify.MatchFilter: The filter that is used to allow the client code additional control over which pattern matches are to be converted into links.
transformFilter Linkify.TransformFilter: Filter to allow the client code to update the link found.

addLinks

Added in API level 24
boolean addLinks (Spannable spannable, 
                Pattern pattern, 
                String defaultScheme, 
                String[] schemes, 
                Linkify.MatchFilter matchFilter, 
                Linkify.TransformFilter transformFilter)

将正则表达式应用于Spannable,将匹配转换为链接。

Parameters
spannable Spannable: Spannable whose text is to be marked-up with links.
pattern Pattern: Regex pattern to be used for finding links.
defaultScheme String: The default scheme to be prepended to links if the link does not start with one of the schemes given.
schemes String: Array of schemes (eg http://) to check if the link found contains a scheme. Passing a null or empty value means prepend defaultScheme to all links.
matchFilter Linkify.MatchFilter: The filter that is used to allow the client code additional control over which pattern matches are to be converted into links.
transformFilter Linkify.TransformFilter: Filter to allow the client code to update the link found.
Returns
boolean True if at least one link is found and applied.

addLinks

Added in API level 1
boolean addLinks (Spannable text, 
                Pattern pattern, 
                String scheme)

将正则表达式应用于Spannable,将匹配转换为链接。

Parameters
text Spannable: Spannable whose text is to be marked-up with links
pattern Pattern: Regex pattern to be used for finding links
scheme String: URL scheme string (eg http://) to be prepended to the links that do not start with this scheme.
Returns
boolean

addLinks

Added in API level 1
boolean addLinks (Spannable text, 
                int mask)

扫描提供的Spannable的文本,并将掩码中指定的所有链接类型转换为可点击的链接。 如果掩码不为零,则还会删除附加到Spannable的所有现有URLSpans,以避免在同一文本中重复调用它时出现问题。

Parameters
text Spannable: Spannable whose text is to be marked-up with links
mask int: Mask to define which kinds of links will be searched.
Returns
boolean True if at least one link is found and applied.

addLinks

Added in API level 1
void addLinks (TextView text, 
                Pattern pattern, 
                String scheme)

将正则表达式应用于TextView的文本,将匹配转换为链接。 如果找到链接,则将UrlSpans应用于链接文本匹配区域,并将文本的移动方法更改为LinkMovementMethod。

Parameters
text TextView: TextView whose text is to be marked-up with links
pattern Pattern: Regex pattern to be used for finding links
scheme String: URL scheme string (eg http://) to be prepended to the links that do not start with this scheme.

addLinks

Added in API level 1
boolean addLinks (Spannable spannable, 
                Pattern pattern, 
                String scheme, 
                Linkify.MatchFilter matchFilter, 
                Linkify.TransformFilter transformFilter)

将正则表达式应用于Spannable,将匹配转换为链接。

Parameters
spannable Spannable: Spannable whose text is to be marked-up with links
pattern Pattern: Regex pattern to be used for finding links
scheme String: URL scheme string (eg http://) to be prepended to the links that do not start with this scheme.
matchFilter Linkify.MatchFilter: The filter that is used to allow the client code additional control over which pattern matches are to be converted into links.
transformFilter Linkify.TransformFilter: Filter to allow the client code to update the link found.
Returns
boolean True if at least one link is found and applied.

addLinks

Added in API level 1
boolean addLinks (TextView text, 
                int mask)

扫描提供的TextView的文本,并将掩码中指定的所有链接类型转换为可点击的链接。 如果找到匹配项,则TextView的移动方法将设置为LinkMovementMethod。

Parameters
text TextView: TextView whose text is to be marked-up with links
mask int: Mask to define which kinds of links will be searched.
Returns
boolean True if at least one link is found and applied.

Hooray!