How to get WebView to ignore css - android

I am trying to load a local HTML page in an Android Webview. This page contains some layouting using CSS. But I also noticed that the Webview has a setBackgroundColor() method in which you can set a background color. however this does not work when the CSS file also set a background color.
Does anyone know how to make the Android Webview to ignore these CSS style when I set my own background color?

What you could do is add style to your page with javascript:
webview.loadUrl("javascript:document.body.style.background = color;");
Call this after you have loaded your url or html.
PS I think if you ignored the CSS you would the get the default white background even if you set setBackGroundColor()
setBackGroundColor is a method that all Views have, that's the only reason WebView has it imo.

Related

android:background is not working with WebView?

For some reason im unable to change the background color of an empty webView in xml using android:background. Although I could change it in java code using something like this:
myWebView.setBackgroundColor(Color.parseColor("#D4CAB4"));
But I prefer to do it in xml and I cant find the reason why android:background is not working?
If one can set WebView background color in xml layout the answer is "NO" and the reason behind is:
Set Background Color of WebView. (XML LAYOUT)
You load data on webView in activity class.
The background you set in the step 1 will be ignored and default color will be set.
The only method left is to set the background of WebView after the data is loaded.
I hope this can help you to understand the case here.

Is possible to render any page which user want but to load some local style like style='color:white;?

I have WebView control on my page and I need to change default font settings like color and font. Is possible to render any page which user want but to load some local style like style='color:white; ? Where to put css and how to load css ?

Android WebView no selection color

In my application I have a webView that contains the FB like button.
JS is enabled to get redirected.
Now my problem is, I want to get rid of the orange selector.
I know this can be done by css, but where do I put my Css file , and how to apply it to my webView?
or is there a other way to accomplish this ?
found it!
webView.setFocusable(false);

WebView selector drawable

how can I change the focus color/drawable in WebView via Java or XML, that is visible on screen below (the orange thing around href)?
I'm afraid you can't do that. This is the default focus style installed on the phone.
this can only be modified by the website itself using css styling.

Change Background color and font color

I want to change my WebView's background color and font size.
Assuming that you have defined your webview in an XML layout resource you can do the following:
WebView myWebView = (WebView) findViewById(R.id.myWebView);
myWebView.setBackgroundColor(Color.parseColor("#000000"));
myWebView.getSettings.setDefaultFontSize(10);
You may also want to enable javascript and create a simple WebClient to handle page loading
Hope it helps!
You could call some javascript that would modify the CSS of the loaded page.
I would think you can't - unless you control the html data displayed.
The font and background are controlled by the html data feed to the Webview and not the Webview itself.

Categories

Resources