如何在Android 4.4+上运行时忽略Cordova App的字体大小设置更改? [英] How to ignore font-size setting changes for Cordova App when runs on Android 4.4+?

查看:1093
本文介绍了如何在Android 4.4+上运行时忽略Cordova App的字体大小设置更改?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发了Cordova App with Cordova 3.6.3版和JQuery。我仍然无法得到最好的解决方案的唯一的一个问题是,当我测试我的应用程序在Android 4.4+和有用户喜欢改变字体大小在设置>显示>设备的字体大小比正常大。它导致我的应用程序布局显示丑陋(最好的显示是当字体大小设置是正常的)。但是对于4.4以前版本的Android(4.3,4.2 ...)的字体大小设置没有效果所以应用程序完美地显示在旧版本。



解决方案我已经应用于我的应用程序是创建自定义插件来检测配置更改,它会检测用户是否使用Android 4.4+,如果他们将字体大小设置为任何不正常,我会使用JQuery强制font-



p> if(font_scale == huge)
{
$(div)。css(font-size,20px!important);
}

这很好,但有时在页面加载后,css不会更改我想要的。并假设如果在那个页面上有30个div,那么我必须插入上面的语句30次,并且它不必要地花费太多的时间。



我只是想知道,还有其他方法来解决这个问题,比使用这个插件更容易吗?也许使用一些XML配置或CSS3属性,可以使我的应用程序显示正常,没有从Android 4.4的字体大小设置的副作用?



另一种方式,我也试过, 't works are


  1. 在Androidmanifest.xml> activity标签上插入fontScale

  2. 插入webkit- -size-adjust:none; in css

我很乐意听到任何有助于解决这个问题的想法。

解决方案

所以你只想忽略系统字体首选项。
以下是解决方案,我使用 MobileAccessibilty插件忽略系统字体首选项



您只需在index.js的onDeviceReady函数中编写以下代码

  if(window.MobileAccessibility){
window.MobileAccessibility.usePreferredTextZoom(false);
}

usePreferredTextZoom(false)将忽略系统字体首选项。 :) :):)


I've developed Cordova App with Cordova Version 3.6.3 and JQuery. The only one problem that i still can't get the best solutions is when i test my app on Android 4.4+ and there are users who love to change font size in setting > display > font-size of their device to be larger than normal. It causes my app layout displays ugly (the best display is when the font-size setting is normal only). But there is no effect of font-size setting for Android older than 4.4 (4.3,4.2...) So the app displays perfectly on older version.

The solutions that I've applied to my app is creating the custom plugin to detect configuration changed and it will detects if user uses Android 4.4+ and if they set font-size setting to anything that is not normal, I'll use JQuery to force font-size to the specified size.

Example is....

if (font_scale == huge)
{
    $("div").css("font-size","20px !important");
}

This works fine but sometimes after the page loaded, the css doesn't changes as I want. And suppose if there are 30 divs+ on that page so i must insert the statement like above 30 times and it takes too much time needlessly.

I just want to know, are there another ways to solve this problem that is easier than using this plugin? Maybe using some XML configuration or CSS3 properties that can makes my app displays properly without side effect from font-size setting of Android 4.4?

Another ways I also tried and it doesn't works are

  1. inserting fontScale on Androidmanifest.xml > activity tag
  2. inserting webkit-text-size-adjust:none; in css

I'd love to hear any ideas that help to solve this.

解决方案

So you just want to ignore the system font preferences. Here is the solution,I use MobileAccessibilty Plugin to ignore the system font preferences.

You just have to write following code in your onDeviceReady function in index.js

if(window.MobileAccessibility){
    window.MobileAccessibility.usePreferredTextZoom(false);
}

usePreferredTextZoom(false) will just ignore the system font preferences. :) :) :)

这篇关于如何在Android 4.4+上运行时忽略Cordova App的字体大小设置更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆