如果你在內部文件中存儲你的CSS你可以使用
//Get a reference to your webview
WebView web = (WebView)findViewById(R.id.webby);
// Prepare some html, it is formated with css loaded from the file style.css
String webContent = "<!DOCTYPE html><html><head><meta charset=\"UTF-8\"><link rel=\"stylesheet\" href=\"style.css\"></head>"
+ "<body><div class=\"running\">I am a text rendered with INDIGO</div></body></html>";
//get and format the path pointing to the internal storage
String internalFilePath = "file://" + getFilesDir().getAbsolutePath() + "/";
//load the html with the baseURL, all files relative to the baseURL will be found
web.loadDataWithBaseURL(internalFilePath, webContent, "text/html", "UTF-8", "");
謝謝!那正是我需要的。 (順便說一句,你可以在內聯HTML中使用單引號而不是雙引號;這樣你就不需要反斜槓了。總是看起來有點整齊......) – 2012-01-06 17:57:19
不錯。我會把PS作爲直接的答案:如果你使用WebView.loadUrl(「file:///android_asset/fname.html」)加載你的html文件;你可以簡單地使用它內的相關網址。 – fortboise 2014-01-31 23:19:49