editText.setLinksClickable(true);
editText.setAutoLinkMask(Linkify.WEB_URLS);
editText.setMovementMethod(CustomMovementMethod.getInstance());
//If the edit text contains previous text with potential links
Linkify.addLinks(editText, Linkify.WEB_URLS);
然后,在用户键入时管理url看起来像链接
editText.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
Linkify.addLinks(s, Linkify.WEB_URLS);
}
});
val message: String = String.format(
getString(R.string.message_content),
firstNameEditText.text,
lastNameEditText.text,
dateTextView.text,
timeTextView.text
)
val gMapURL = getString(R.string.google_map_location)
// Setup my Spannable with clickable URLs
val spannable: Spannable = SpannableString(gMapURL)
Linkify.addLinks(spannable, Linkify.WEB_URLS)
// Append a zero-width space to the Spannable
val gText = TextUtils.concat(spannable, "\u200B")
val finalText = TextUtils.concat(message, gText)
messageContentEditText.setText(finalText)
4条答案
按热度按时间gwbalxhn1#
XML:
JAVA:
up9lanfz2#
对于编辑文本,我设法通过以下方式获得可点击的链接。首先,我实现了一个自定义的MovementMethod,描述为here
java
(从xml或上下文创建编辑文本)
然后,在用户键入时管理url看起来像链接
rjjhvcjd3#
希望这能帮助到一些人
velaa5lx4#
XML -将其写入EditText