以下编码:
private WebView mWebView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getSupportActionBar().hide();
setContentView(R.layout.activity_main);
mWebView = (WebView) findViewById(R.id.webView);
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
mWebView.setWebViewClient(new WebViewClient() {
@Override
public WebResourceResponse shouldInterceptRequest(final WebView view, String url) {
if (url.contains("tamil.css")) {
return getCssWebResourceResponseFromAsset();
} else {
return super.shouldInterceptRequest(view, url);
}
}
private WebResourceResponse getCssWebResourceResponseFromAsset() {
try {
return getUtf8EncodedCssWebResourceResponse(getAssets().open("tam.css"));
} catch (IOException e) {
return null;
}
}
private WebResourceResponse getUtf8EncodedCssWebResourceResponse(InputStream data) {
return new WebResourceResponse("text/css", "UTF-8", data);
}
});
mWebView.loadUrl("http://www.example.com/Mobile/mob/aa.html");
}
css文件:
body{background:url('tamil.jpg');}
h1{color:#cfc;}