Webview 載入文章內容
設定listview的點選事件
ListView newslistView=(ListView) findViewById(R.id.show_news);
newslistView.setAdapter(new NewsAdapter(newss,NewsActivity.this,newslistView));
newslistView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent intent = new Intent(NewsActivity.this,ArticleActivity.class);
News news = newss.get(position);
String AtUrl = "http://news-at.zhihu.com/api/4/news/"+news.getId();
intent.putExtra("AtUrl",AtUrl);
startActivity(intent);
}
});
新建WebView,通過url獲取html內容,問題是載入css的過程。webview.load()
這個方法會出現亂碼,查過之後發現要手動設定編碼方式為utf8
WebView wv = (WebView)findViewById(R.id.webview);
String content = getUnicodeContent();
wv.getSettings().setDefaultTextEncodingName(“UTF -8”);
wv.loadData(content, “text/html”, “UTF-8”) ;
但仍沒有解決亂碼,所以改用loadDataWithBaseURL()
* @param baseUrl the URL to use as the page's base URL. If null defaults to
* 'about:blank'.
* @param data a String of data in the given encoding
* @param mimeType the MIMEType of the data, e.g. 'text/html'. If null,
* defaults to 'text/html'.
* @param encoding the encoding of the data
* @param historyUrl the URL to use as the history entry. If null defaults
* to 'about:blank'. If non-null, this must be a valid URL.
*/
public void loadDataWithBaseURL(String baseUrl, String data,
String mimeType, String encoding, String historyUrl) {
checkThread();
mProvider.loadDataWithBaseURL(baseUrl, data, mimeType, encoding, historyUrl);
}
載入css的方法貌似有很多,比如用js,但最後選擇了在以下方案。
要注意的是獲取到的html程式碼不一樣的情況下面的程式碼是有問題的,所以這個方法是偷懶的權宜之計
WebView webview = (WebView) findViewById(R.id.ArticleView);
String html = "<html><header><style type='text/css'>"+css+"</style></header>"
+"<body>"+body+"</body></html>";
webview.loadDataWithBaseURL(null,html, "text/html", "utf-8", null);
相關文章
- 網站文章內容修改 如何修改網站文章內容網站
- 文章內容提取庫 goose 簡介Go
- 文章內容分頁功能實現
- 對於動態載入內容 (包括 Ajax 請求內容) 繫結點選事件事件
- 發表文章時提示有垃圾內容?
- 優化 WebView 的載入速度例項優化WebView
- 解決Bilibili無法選中文章內容
- iOS 精準獲取webView內容高度並自適應高度iOSWebView
- Android 8.0上webView載入url,不回撥onPageFinishedAndroidWebView
- canvas 寫入文字內容Canvas
- php文章內容替換為內鏈,有助於SEO優化PHP優化
- PHP顯示文章內容點選數加一PHP
- python excel 內容寫入mysqlPythonExcelMySql
- 文章錯別字檢測,提升你的內容質量,幫你進行內容分發
- Laravel 中使用 puppeteer 採集非同步載入的網頁內容Laravel非同步網頁
- jQuery寫的文章內容頁右側浮動滾動jQuery
- 織夢DedeCMS文章內容分頁頁數控制方法教程
- 一篇用AI生成圖片與內容的文章AI
- jquery製作圖片瀑布流點選按鈕載入更多內容jQuery
- 直播原始碼,下拉重新整理和上劃預載入新內容原始碼
- 十五章 CI框架學習筆記(二)載入靜態內容框架筆記
- python操作檔案寫入內容Python
- Flutter下實現WebView攔截載入離線資源FlutterWebView
- Android WebView適配html載入本地檔案並上傳AndroidWebViewHTML
- 如何使用ScrapySharp下載網頁內容網頁
- 帝國cms把文章內容都存放到根目錄方法
- PbootCMS後臺新增文章內容增加隨機訪問數量boot隨機
- 工作踩坑系列——https 訪問遇到 “已阻止載入混合活動內容”HTTP
- git將指定內容寫入檔案Git
- offsetLeft offsetTop // DOM操作,之寫入內容
- 小程式 webview 應用實踐(演講內容整理)丨掘金開發者大會WebView
- 如何讓excel單元格內只能輸入指定內容?Excel
- WordpressCMS主題開發08-CMS文章內容頁面的製作
- 關於iOS Webview 載入React 靜態資源的安全問題iOSWebViewReact
- python自動開啟瀏覽器下載zip,並且提取內容寫入excelPython瀏覽器Excel
- app直播原始碼,監聽EditText輸入框內輸入內容的變化APP原始碼
- 使用了`wreq`庫來下載網頁內容網頁
- 全域性負載均衡與CDN內容分發負載
- Webview載入html後,數字會顯示藍色可點選呼叫WebViewHTML