[英]Multiline text in EditText with links, both clickable and editable
I am working with multiline EditText view which can contain webUrl in input.我正在使用多行 EditText 视图,它可以在输入中包含 webUrl。 For that I am using LinkMovementMethod
make links in the EditText clickable.为此,我使用LinkMovementMethod
使 EditText 中的链接可点击。
I have the same problem as the question EditTexts with links both clickable and editable , but also I have multiline text.我有与EditTexts问题相同的问题,其中包含可点击和可编辑的链接,但我也有多行文本。
Problem is that:问题在于:
If the last part of string is a link, clicking anywhere causes the link to be opened.如果字符串的最后一部分是链接,单击任意位置会打开链接。
Extensions:扩展:
When I am clicking in current area of EditText, It will be editable.当我单击 EditText 的当前区域时,它将是可编辑的。 https://i.stack.imgur.com/DBKAX.png https://i.stack.imgur.com/DBKAX.png
Example:例子:
XML layout: XML布局:
<EditText
android:id="@+id/description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:autoLink="web"
android:gravity="start"
android:hint="@string/Event_Description"
android:inputType="textCapSentences|textMultiLine"
android:minLines="12"
android:textColorLink="@color/link_color"
android:textIsSelectable="true" />
Code example:代码示例:
etDescription = findViewById(R.id.description);
etDescription.addTextChangedListener(descriptionTextWatcher);
etDescription.setMovementMethod(LinkMovementMethod.getInstance());
private TextWatcher descriptionTextWatcher = 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);
}
};
Temporally I realize LongClick reaction, but I find this solution awkward, and I want to make it better.暂时我意识到 LongClick 反应,但我觉得这个解决方案很尴尬,我想让它变得更好。
Code example:代码示例:
etDescription.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View view) {
etDescription.requestFocus();
InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.showSoftInput(etDescription, InputMethodManager.SHOW_IMPLICIT);
return true;
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.