禁用 WebView 中的可选链接

发布于 2024-12-18 17:49:00 字数 329 浏览 5 评论 0原文

我有一个包含在 scrollView 中的 webView。所有内容都包含在 viewPager 中。当我跳到下一个视图页面时,页面中间的链接将被聚焦(文本周围以橙色突出显示)。这会导致页面跳转到最近的链接。

有没有办法禁止链接在触摸时聚焦?我已经尝试了 webView 的所有设置,例如 focusable = falseclickable = falsefocusable in touch mode = false,似乎没有任何效果。

I have a webView that is contained within a scrollView. Everything is then contained within a viewPager. When I fling to the next view page, the links that are in the middle of the page are being focused (highlighted with orange around the text). This causes the page to jump down to the nearest link.

Is there a way to disable links from being focusable on touch? I've tried all the settings for the webView such as focusable = false, clickable = false, focusable in touch mode = false, and nothing seems to be working.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

放血 2024-12-25 17:49:00

我设法以编程方式做到这一点,如下所示:

WebView myWebView = (WebView) storyItem.findViewById(R.id.myWebView);
myWebView.setFocusableInTouchMode(false);
myWebView.setFocusable(false);

这使得链接不可聚焦,这解决了我的问题!

I managed to do it programmatically like so:

WebView myWebView = (WebView) storyItem.findViewById(R.id.myWebView);
myWebView.setFocusableInTouchMode(false);
myWebView.setFocusable(false);

This makes the links non-focusable, which solved my problem!

绅刃 2024-12-25 17:49:00
    webView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            return true;
        }
    });
    webView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            return true;
        }
    });
安静 2024-12-25 17:49:00
Webview.setWebViewClient(new WebViewClient(){
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {                  
                        return true;
            }
        });

这可以防止网络视图打开任何链接,并且还可以让您毫无问题地导航页面

Webview.setWebViewClient(new WebViewClient(){
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {                  
                        return true;
            }
        });

This prevents the webview from opening any links and will also allow you to navigate the page without problems

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文