I have a WebView that is formatted via a CSS file - I dynamically generate HTML from the application for this view, as the web server does. The generated HTML refers to a static CSS file for formatting. I have an image formatting instruction, for example:
img { width: 20px; height: 20px; }
To make this device independent, I would like to use dip, and instead px to measure width and height. I cannot understand (and cannot find) how to specify dip as a unit in the css definition. I tried "dp" and "dip", none of which worked. It can be done?
I know that I can have several versions of the CSS file that are selected using the selector type <"target-densitydpi = high-dpi">, but this means that I will have duplicate CSS files only for the possibility, depending on the density of the device. Doable, but I would rather be able to specify dip in the CSS file and make WebView work for me.
It would also be feasible to create an inline style sheet in the head of HTML and convert dip to px for a specific device, but this will lead to a connection between the CSS definition and the HTML generation code. Probably better than a few CSS files (for my application), but it would be much better to just skip the dip in the CSS file and do with it.
(My images are designed to resize without artifacts for the range of currently supported screen densities)
android css webview
Colin
source share