实施“复制链接文本”功能在应用程序中 [英] Implement "Copy Link Text" feature in the app

查看:132
本文介绍了实施“复制链接文本”功能在应用程序中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有显示搜索结果的Android WebView。使用 contextMenu 和WebView HitTestResult ,我已经成功实现了打开,保存,复制链接url等选项列表。现在,我想实现复制链接文本功能在Google chrome android中应该只复制链接文本(标题)。类似的(不是精确的)功能在默认的Android浏览器中显示为选择文本选项。
我不希望使用剪贴板复制文本的代码,而是我的主要格言是确定检索链接标题
链接网址可以使用 HitTestResult getExtra()方法检索,还有什么方法可以检索链接文本(标题)吗?

我引用了如何在Android WebView中获取加载的网页标题?,但它会在加载网页后给出标题,而不是链接被按下时。

不幸的是,您发布的链接是获​​取页面标题的最快方式(您可以参考第二个答案,这可能会更快)。



背后的原因是我们在阅读页面标题之前,需要加载bsite。 onReceivedTitle()(链接的第二个答案)的优点是它不会等到整个页面加载完毕。它会一直等到足够的时间从文档中检索标题。它也会在每次页面标题发生变化时通知您(由于JavaScript或其他原因)。



编辑:

chrome用于复制链接文本的功能是复制文本链接如下:

 < a href =linkUrl>链接文字< / a> 

这很难通过webview来实现,因为您需要访问html的内容网页。这里有一些解决方法(请参阅此处)。



这两个API( selectText and copySelection 正在等待API理事会批准,他们会帮助你做到这一点,但目前还没有。



这是不可用的。


I have Android WebView which displays search results. Using the contextMenu and WebView HitTestResult, I have successfully implemented a list of options like open, save, copy link url.
Now, I would like to implement copy link text feature as present in Google chrome android which should copy only link text (title). A similar(not exact) feature is present in default Android browser as "Select text" option.
I don't want the code for copying text using clipboard instead my main motto is to determine the way of retrieving the link title.
The link url can be retrieved using HitTestResult getExtra() method likewise is there any way to retrieve the link text (title) ?
I have referred How to get loaded web page title in Android WebView? but it gives title after the webpage is loaded not when the link is pressed.

解决方案

Unfortunately, the link you posted is the fastest way to get the page title (you may refer to the second answer, which is probably faster).

The reason behind this is that a website needs to be loaded before you can read the page title. The advantage of onReceivedTitle() (the second answer of your link) is that it doesn't wait until the whole page is loaded. It waits until enough is loaded to retrieve the title from the document. It also notifies you every time the page title gets change (due to JavaScript or whatever).


Edit:
What chrome does with Copy link text is to copy the text of the link like this:

<a href="linkUrl">Linktext</a>

This is very difficult to achieve via a webview, since you need access to the html-content of the webpage. There are some workarounds out there (see here).

The are two APIs (selectText and copySelection) which are pending API council approval, they would help you to do this, but they are not available at the moment.

A clear, official way to do this is not available.

这篇关于实施“复制链接文本”功能在应用程序中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆