I'm loading a page in a Android app with a WebView
(=embedded browser in app), with standard settings:
mywebView = (WebView) findViewById(R.id.activity_main_webview);
...
mywebView.loadUrl("http://example.com/test");
Everything works correctly except the following minor issue:
Problem: The 1-pixel-wide border is not displayed correctly: one or two of the four sides of the border are 2px instead of 1px. It looks like this:
I noticed that
window.devicePixelRatio = 1.5
on my deviceHere is the HTML code (I don't use a code snippet, because they are not runnable on mobile devices anyway):
<html> <head> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <style type="text/css"> #test { display: inline-block; border: 1px solid #c4c4c4; padding: 9px; } </style> </head> <body> <a id="test">Test</a> </body> </html>
The solutions given in this question (I have put a bounty there, so I already tested the answers) don't work:
border: 0.5px solid black;
orborder: 0.75px solid black;
show no border at all, so this is not a duplicate. This is a specific question whendevicePixelRatio = 1.5
(it behaves different than1
or2
)Live demo here, I cannot reproduce the problem in Chrome for Android, but only in a Android app using
WebView
and displaying the same page (strange, isn'tWebView
using the same rendering engine as Chrome?)