简体   繁体   English

Android 辅助功能对讲 - 在 TextView 的超链接上处理 onClick

[英]Android Accessibility Talkback - handle onClick on hyperlink of TextView

We have a text view which supports HTML tags.我们有一个支持 HTML 标签的文本视图。 In this text view, the text will come in the form of HTML and we are able to populate it perfectly.在这个文本视图中,文本将以 HTML 的形式出现,我们可以完美地填充它。 The text may contain, some hyperlinks.文本可能包含一些超链接。 These hyperlinks are in regular <a href> tags.这些超链接位于常规<a href>标记中。

The catch here is that these hyperlinks may be outside URLs or reference path to internal Activities.这里要注意的是,这些超链接可能是外部 URL 或内部活动的引用路径。

The functionality works fine.该功能工作正常。 But during Talkback feature, the internal paths are not calling the onClick method to call respective intents and throws an error但是在Talkback功能期间,内部路径没有调用onClick方法来调用各自的意图并抛出错误

Error错误

W/URLSpan: Actvity was not found for intent, Intent { act=android.intent.action.VIEW dat=/abc/xyz/CONTACT_US (has extras) }

The below code is our handler to capture onClick and open the respective page.下面的代码是我们捕获 onClick 并打开相应页面的处理程序。 But this method is not firing during talkback.但是这种方法在对讲期间不会触发。 Rather, the URL is taken from the text itself.相反,URL 取自文本本身。 Is there a way to override talkback to use our method?有没有办法覆盖对讲来使用我们的方法?

Code for the method to handle hyperlink clicks.处理超链接点击的方法的代码。

CustomLinkMovementMethod.linkify(Linkify.ALL, text)
                        .setOnLinkClickListener(new CustomLinkMovementMethod.OnLinkClickListener() {
                            @Override
                            public boolean onClick(TextView textView, String url) {
                                Log.d(TAG, "onClick: " + url);
                                if (mContext instanceof Activity) {
                                    ((Activity)mContext).handleLink( url );
                                }
                                return false;
                            }
                        });

I removed the CustomLinkMovementMethod and in its place used a Custom URLSpan class to capture hyperlinks embedded in the HTML texts我删除了 CustomLinkMovementMethod 并取而代之的是使用自定义 URLSpan class 来捕获嵌入在 HTML 文本中的超链接

Custom URL Span class is similar to the accepted answer in the following StackOverflow question自定义 URL 跨度 class 类似于以下StackOverflow 问题中接受的答案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM