Change Background color and font color - android

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.

Related

Change font in webview code programmatically

I have a problem. I have to change the font in my webview. I mean I have a html page in assets and font of the html page is default font. I want to change font of the html page but it must be done in code in android application. This is possible?

How to get WebView to ignore css

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.

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: How to load a page into a WebView and then apply some custom css to it?

I need to load a page into a webview and then apply some custom css to it. This page is not under my control, so I can't simply add a CSS include or inline CSS within the page itself.
Right now I'm just doing an HTTP get request, putting the contents into a String, prepending the string with my custom css (in style tags), and finally doing a loadDataWithBaseURL() on the string.
Is there a more elegant/efficient solution?
Thanks!
Well using what is available in the Webview, you have probably done the best that could be done.
However, if you really want to do it elegantly, get the source codes of WebView and all the classes it needs. Alter them to ultimately add the function WebView.setCSS() (for example)... It is doable but it needs some time.
you can just try WebView.reload() just like :
if(first_loading){
w.loadUrl(DisplayActiviyParam.sd_html);
first_loading = false;
}else{
w.reload();
}
,what you need do is tu change your css file contents. Good lucky!

Problems with WebView appearance

I want to customize text (font, size, color...) which is displayed on a picture. I decided to use WebView as I'm not sure how to use (and is it possible at all???) HTML/CSS inside a TextView. The problem is that a WebView has its own background(white) though which I can't see my picture. setBackgroundDrawable(null); did not help.
Use an imageview and textview inside of an absolutelayout or relativelayout. Then align the two views to different sides of the layout and use margins and gravity to space them correctly. Using a webview for images and text when there is no need seems pointless if they are not on a webpage.
http://developer.android.com/resources/articles/layout-tricks-merge.html
To add a font to your project, create a new folder called "assets" in your root. inside there creates a folder "fonts" and in there, place your .ttf file. Here is a link:
How to add external fonts to android application
You might be able to use yourWebView.setBackgroundResource(R.drawable.yourImage); But I am not 100% sure that WebViews support that method. Another option would be to put the Image in the html that you are using though. That might be the easiest way to go about making it look exactly how you want.
You can try this out..
public class Hello extends Activity {
WebView mWebView;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.hello);
mWebView = (WebView) findViewById(R.id.webviewactive);
String text =
mWebView.loadData(text, "text/html", "utf-8");
mWebView.setBackgroundColor(0);
OK, so I found the answer. If you want to make the background of WebView transparent, just write in your .xml file android:alpha="0". To retrieve HTML-tags in Android, implement a TagHandler interface. There is an example here.

Categories

Resources