答案 0 :(得分:1)
此功能称为 Rich Link 。
使用Android Link Preview Library
可以轻松实现富链接通过在gradle中添加以下内容来实现
添加以下存储库
repositories {
jcenter()
maven { url 'https://github.com/leonardocardoso/mvn-repo/raw/master/maven-deploy' }
}
添加以下gradle文件
compile 'org.jsoup:jsoup:1.8.3' // required
compile 'com.leocardz:link-preview:2.0.0@aar'
如果您使用的是Proguard规则,请添加以下规则
-keeppackagenames org.jsoup.nodes
实施
<强> Intialisation 强>
import com.leocardz.link.preview.library.TextCrawler;
// ...
// Create an instance of the TextCrawler to parse your url into a preview.
TextCrawler textCrawler = new TextCrawler();
// ..
// Create the callbacks to handle pre and post exicution of the preview generation.
LinkPreviewCallback linkPreviewCallback = new LinkPreviewCallback() {
@Override
public void onPre() {
// Any work that needs to be done before generating the preview. Usually inflate
// your custom preview layout here.
}
@Override
public void onPos(SourceContent sourceContent, boolean b) {
// Populate your preview layout with the results of sourceContent.
}
};
生成预览
textCrawler.makePreview( linkPreviewCallback, url);
请试试这个