[英]EditTexts with links both clickable and editable
Daniel Lew几天前写了关于它的博客文章。 他建议下一个解决方案
// Make links in the EditText clickable
editText.setMovementMethod(LinkMovementMethod.getInstance());
// Setup my Spannable with clickable URLs
Spannable spannable = new SpannableString("http://blog.danlew.net");
Linkify.addLinks(spannable, Linkify.WEB_URLS);
// The fix: Append a zero-width space to the Spannable
CharSequence text = TextUtils.concat(spannable, "\u200B");
// Use it!
editText.setText(text);
你可以在这里找到帖子: 使用可点击和可编辑的链接制作EditTexts
检查以下代码。
EditText inputText;
//Edittext is clickable at right side.
inputText.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
final int DRAWABLE_LEFT = 0;
final int DRAWABLE_TOP = 1;
final int DRAWABLE_RIGHT = 2;
final int DRAWABLE_BOTTOM = 3;
if (event.getAction() == MotionEvent.ACTION_UP) {
if (event.getRawX() >= (inputText.getRight() - inputText.getCompoundDrawables()[DRAWABLE_RIGHT].getBounds().width())) {
//write your logic
return true;
}
}
return false;
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.