慕無忌1623718
2021-10-20 11:24:33
我有一個 WebView。它包含頁面,由 Jsoup 過濾。 WebView cntContent; WebView cntComments; WebSettings webSettingsContent; WebSettings webSettingsComments; cntContent = findViewById(R.id.cntContent); cntComments = findViewById(R.id.cntComments); webSettingsContent = cntContent.getSettings(); webSettingsComments = cntComments.getSettings(); webSettingsContent.setDefaultFontSize(16); webSettingsComments.setDefaultFontSize(16); cntContent.setBackgroundColor(Color.TRANSPARENT); cntComments.setBackgroundColor(Color.TRANSPARENT); webSettingsContent.setAppCacheEnabled(true); webSettingsComments.setAppCacheEnabled(true); cntContent.loadDataWithBaseURL(contentUrl, contentFinal, "text/html", "utf-8", null); cntComments.loadDataWithBaseURL(contentUrl, commentsFinal, "text/html", "utf-8", null); cntContent.setClickable(true);頁面包含鏈接。當(dāng)用戶單擊鏈接并將 url 放入字符串時,如何提供鏈接的 url?
1 回答

慕慕森
TA貢獻(xiàn)1856條經(jīng)驗(yàn) 獲得超17個贊
您應(yīng)該做的是為 WebView 提供您自己的 WebViewClient。子類化 WebViewClient 并使用 WebView 方法 setWebViewClient 對其進(jìn)行設(shè)置。然后在 WebViewClient 中覆蓋“shouldOverrideUrlLoading”方法并使用鏈接執(zhí)行任何您喜歡的操作。
WebView wv = new WebView();
wv.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
String url = request.getUrl().toString();
return false;
}
});
添加回答
舉報
0/150
提交
取消