Android Question WebView with CSS

b4xscripter

Member
Licensed User
Longtime User
Hi,
first of all, maybe this question is duplicated but I didn't find a clear response.
I use for my project the WebView library that works fine. But, sometimes, I have problems related to the styles. When I load a page the page is losing for 1-2 seconds the style (CSS) that, passed this time, is shown correctly. Please find attached images: the left one is shown in the first 1-2 seconds. The second one is shown passed 1-2 seconds.
I know that the problem is probably related to the fact that first the web is loeaded completely and after the styles are applied. But maybe someone has a trick to load the page in a different manner?
Thanks in advance!
 

Attachments

  • styles.png
    styles.png
    435.7 KB · Views: 314

nwhitfield

Active Member
Licensed User
Longtime User
Are the styles loaded from the HTML using a link rel tag?

Assuming you have control over the web pages, you could try putting them in line in the HTML file, so that the browser reads them, before it gets to the page layout.

I'm suggesting that because my suspicion is that they're loaded in the usual way, with a line in the page header that's something like

B4X:
<link href="/layout/fonts.css" rel="stylesheet" type="text/css">

and that when the WebView sees that, it carries on rendering the page, while firing off an asynchronous request to fetch the stylesheet. When that arrives, it applies it to the page.

Try instead putting the contents of your CSS file inline using style tags, and see if that makes a difference.
 
Upvote 0

b4xscripter

Member
Licensed User
Longtime User
Hi, Erel,

My CSS files are in my server, not in local. Is it possible to use CSS in local for webview?

Regards
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0
Top