Phonegap - Ignore font-size display setting on And

2020-02-26 09:25发布

问题:

I'm having an issue with some android devices when changing the font-size display setting through configuration.

In web browser my app is simple ignoring this. This is true for some other mobiles too.

But with some specific mobiles (like Motorola G or X) changing this config also affects my Phonegap app.

I don't know how to avoid this to make the app look consistent

回答1:

I've found a solution using this cordova plugin: com.phonegap.plugin.mobile-accessibility

You have to follow installation instructions for the plugin, and then you can use it inside Ionic app. You only have to ensure to call its functions after Cordova 'deviceready' callback (accesed by $ionicPlatform.ready in the example below):

angular.module('app').controller('IndexController', function ($ionicPlatform, $window) {

    $ionicPlatform.ready(function(){
        if($window.MobileAccessibility){
            $window.MobileAccessibility.usePreferredTextZoom(false);
        }
    });
});


回答2:

For anyone using Ionic. Documentation is here.

Install

$ ionic cordova plugin add phonegap-plugin-mobile-accessibility
$ npm install --save @ionic-native/mobile-accessibility

Add to module, i.e. app.module.ts

import { MobileAccessibility } from 'ionic-native';


@NgModule({
    providers:[MobileAccessibility]
});

In app.component.ts

constructor( mobileAccessibility: MobileAccessibility, platform: Platform) {

    platform
      .ready()
      .then(()=>{
          mobileAccessibility.usePreferredTextZoom(false);
      });

}