NickF
NickF

Reputation: 5737

Strange behavior of Android WebView with center tag in Samsung devices

In my application there is a WebView and a button.
on button click I receive a HTML from a webservice with AsyncTask.
There are a situation when I receive the same HTML from the service.

The HTML:

<html>
    <head>
    </head>
    <body style="font-family:Arial;">
        <center>No data to display</center>
    </body>
</html>

The strange behavior:
At every odd call (1, 3, 5, ...) the HTML above is centered, every even call the same HTML that aligned to left.
It happens only on Samsung Galaxy 2 and 3 with Android 4 and not happens on Motorola Atrix with Android 2.3.4.

I load the HTML with:

mReportChart.loadDataWithBaseURL("fake://", data.getHtml(), "text/html", "utf-8", "fake://");

The HTML each time is the same.
How can I resolve that problem?

Upvotes: 0

Views: 668

Answers (2)

Ben P. Dorsi-Todaro
Ben P. Dorsi-Todaro

Reputation: 321

The center tag is deprecated in HTML 4.01 and not supported in HTML 5. I would use CSS to center what you want out.

http://www.w3schools.com/tags/

<div style="text-align: center;">
No data to display
</div>

Upvotes: 0

caiocpricci2
caiocpricci2

Reputation: 7798

Ben is right, the center tag is not standard HTML5, so you can't expect it to work properly. The best solution, if you can, is getting rid of the center tag. But if that's not the case you can just "force" the center tag to be centered with css. Add the following to your stylesheet and it should be fixed:

center {
    margin-left:auto;
    margin-right:auto;
    text-align:center;
}

Upvotes: 2

Related Questions