标签:
<script type="text/javascript">
function changeFontSize(size) {
var tfs = ‘120%‘;
var ifs = ‘100%‘;
var tlh = ‘30px‘;
var ilh = ‘18px‘;
switch (size) {
case 110:
tfs = ‘110%‘;
ifs = ‘90%‘;
tlh = ‘28px‘;
ilh = ‘16px‘;
break;
case 120:
tfs = ‘120%‘;
ifs = ‘100%‘;
tlh = ‘30px‘;
ilh = ‘18px‘;
break;
case 130:
tfs = ‘130%‘;
ifs = ‘110%‘;
tlh = ‘34px‘;
ilh = ‘22px‘;
break;
case 140:
tfs = ‘140%‘;
ifs = ‘120%‘;
tlh = ‘38px‘;
ilh = ‘26px‘;
break;
case 150:
tfs = ‘150%‘;
ifs = ‘130%‘;
tlh = ‘42px‘;
ilh = ‘30px‘;
break;
}
var pNodes = document.getElementsByTagName(‘p‘);
for (var i = 0; i < pNodes.length; i++) {
if (pNodes[i].className == ‘imgtxt‘) {
pNodes[i].style.fontSize = ifs;
pNodes[i].style.lineHeight = ilh;
}
if (pNodes[i].className == ‘txt‘) {
pNodes[i].style.fontSize = tfs;
pNodes[i].style.lineHeight = tlh;
}
}
}
</script>
然后我们用WebView去调用用这个方法就可以了,代码如下
WebView.loadurl("javascript:changeTextSize(size)");
Android--用JS去控制WebView显示的字体的大小
标签:
原文地址:http://www.cnblogs.com/819158327fan/p/5125645.html