android WebViewMarker如何用在访问非本地网页? 10
展开全部
可以用js加载css。
webview.setWebViewClient(new WebViewClient() {
....
public void onPageFinished(WebView view, String url) {
src="file:///android_asset/xxx.js"
String baseUrl = "file:///android_asset";
view.loadDataWithBaseURL(baseUrl, strHtml, "text/html", "utf-8", null);
}
....
}
js文件如下:
function loadjscssfile(filename,filetype){
if(filetype == "js"){
var fileref = document.createElement('script');
fileref.setAttribute("type","text/javascript");
fileref.setAttribute("src",filename);
}else if(filetype == "css"){
var fileref = document.createElement('link');
fileref.setAttribute("rel","stylesheet");
fileref.setAttribute("type","text/css");
fileref.setAttribute("href",filename);
}
if(typeof fileref != "undefined"){
document.getElementsByTagName("head")[0].appendChild(fileref);
}
}
调用方式:
loadjscssfile("test.css","css");
webview.setWebViewClient(new WebViewClient() {
....
public void onPageFinished(WebView view, String url) {
src="file:///android_asset/xxx.js"
String baseUrl = "file:///android_asset";
view.loadDataWithBaseURL(baseUrl, strHtml, "text/html", "utf-8", null);
}
....
}
js文件如下:
function loadjscssfile(filename,filetype){
if(filetype == "js"){
var fileref = document.createElement('script');
fileref.setAttribute("type","text/javascript");
fileref.setAttribute("src",filename);
}else if(filetype == "css"){
var fileref = document.createElement('link');
fileref.setAttribute("rel","stylesheet");
fileref.setAttribute("type","text/css");
fileref.setAttribute("href",filename);
}
if(typeof fileref != "undefined"){
document.getElementsByTagName("head")[0].appendChild(fileref);
}
}
调用方式:
loadjscssfile("test.css","css");
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询