[英]Intercept link LinkMovementMethod with a Yes/No dialog
I have a standard LinkMovementMethod
established in my TextView
to push a web Activity of some sort when the user touches a link. 我在TextView
建立了一个标准LinkMovementMethod
,以在用户触摸链接时推送某种形式的Web Activity。 However, I want to establish a "do you want to see the link" dialog rather than taking the user straight to the webpage. 但是,我想建立一个“您是否想看到链接”对话框,而不是直接将用户带到网页。 I've tried overriding the touch methods but it all gets a little convoluted. 我尝试覆盖触摸方法,但是这一切都有些令人费解。 A little help? 一点帮助?
You can accomplish it in two ways: 您可以通过两种方式完成此任务:
LinkMovementMethod
to accept custom click listener 扩展LinkMovementMethod
以接受自定义点击侦听器 In my opinion second solution is better in basic cases like yours. 我认为,在像您这样的基本情况下,第二种解决方案更好。 Here is how you can do it: 这是您可以执行的操作:
OnLinkClickedListener clickListener = new OnLinkClickedListener() {
@Override
public boolean onLinkClicked(String linkText) {
// here you can handle your click, eg show the dialog
// `linkText` is the text being clicked (the link)
// return true if handled, false otherwise
}
}
yourTextView.setMovementMethod(new InternalLinkMovementMethod(clickListener));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.