Android Webview css get url background image not showing
Android intercept request http-based local store css .. webview get css file. but can't get css background: url ('image.jpg') . I keep my local resources css and jpg folder in the same location but cannot get ...
The coding is below:
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 file:
body{background:url('tamil.jpg');}
h1{color:#cfc;}
+3
source to share
No one has answered this question yet
Check out similar questions: