有没有办法专门为Android指定CSS

时间:2013-08-22 00:54:51

标签: android css google-chrome fonts cordova

我正在开发一个Phonegap应用,并且我的Android设备上的字形高度和边距渲染问题与我的桌面上编译的Phonegap应用程序与Chrome浏览器的字体字体不同。

是否有办法专门为Android的渲染引擎指定CSS样式,类似于CSS中常见的跨浏览器功能(例如-webkit,-moz等)?

我使用的字体是http://www.entypo.com/,我遇到问题的CSS样式是行高和边距。整个应用程序中的常规字体没有遇到任何类似的问题。

2 个答案:

答案 0 :(得分:1)

如果您可以检测到设备/环境,那么您在该设备上专门定位元素的服务就像将一个类附加到页面的<html>标记一样简单。然后从该根类调用您的样式声明。例如:

.wrapper {
    background: blue; /* will apply to all documents independent of device */
}

.android .wrapper {
    background: green; /* will only apply to documents with the .android base class */
}

对于检测设备,这是一个完全不同的问题,但假设您可以检测到该设备,此方法将起作用。

答案 1 :(得分:0)

在Android代码中,您可以在onCreate()

之后添加到loadUrl()
this.sendJavascript("document.getElementsByTagName('body')[0].className = 'android'");

这将为您的<body>添加“android”类,并允许您为Android版本的应用使用特定的CSS选择器。如果您已经在<body>申请了课程,则可以

this.sendJavascript("document.getElementsByTagName('body')[0].className += ' android'");
相关问题