title: How do I prevent Android device Display size scaling in my app?
body: <p>I'm developing an app with React Native for both iOS and Android, and I am trying to prevent device-specific scaling of the display in the app.</p>
  
  <p>For text/font size scaling, putting the following code in the root-level App.js file solves the issue for both iOS and Android:</p>
  
  <pre><code>if (Text.defaultProps == null) {
      Text.defaultProps = {};
  }
  Text.defaultProps.allowFontScaling = false;
  </code></pre>
  
  <p>However, Android devices have the following Display size setting that is still being applied:</p>
  
  <p><a href="https://i.stack.imgur.com/IJoMm.png" rel="noreferrer"><img src="https://i.stack.imgur.com/IJoMm.png" alt="Android Device Display size setting"></a></p>
  
  <p>I've tried (unsuccessfully) to piece together a variety of "solutions" to this issue that I've found in answers to the following questions:</p>
  
  <p><a href="https://stackoverflow.com/questions/37996601/change-the-system-display-size-programatically-android-n">Change the system display size programatically Android N</a></p>
  
  <p><a href="https://stackoverflow.com/questions/50252424/disabling-an-app-or-activity-zoom-if-setting-display-display-size-changed">Disabling an app or activity zoom if Setting -&gt; Display -&gt; Display size changed to Large or small</a></p>
  
  <p><a href="https://stackoverflow.com/questions/21546805/how-to-prevent-system-font-size-changing-effects-to-android-application/32832216#32832216">how to prevent system font-size changing effects to android application?</a></p>
  
  <p>I've often found references to a <code>BaseActivity</code> class that extends the <code>Activity</code> class. My understanding is that it is inside of that class where I would be writing a method (let's call it <code>adjustDisplayScale</code>) to make changes to the <code>Configuration</code> of the <code>Context</code> that I get from <code>Resources</code>, and that then I would be calling <code>adjustDisplayScale</code> within the <code>onCreate()</code> method after <code>super.onCreate()</code> in the <code>MainApplication.java</code> file.</p>
  
  <p>As of now, in this directory I just have two files - <code>MainApplication.java</code> and <code>MainActivity.java</code>. </p>
  
  <p>I've attempted creating a new Module and associated Package file to implement <code>adjustDisplayScale</code> following these instructions and it did not work:
  <a href="https://facebook.github.io/react-native/docs/text.html" rel="noreferrer">https://facebook.github.io/react-native/docs/text.html</a></p>
  
  <p>I've attempted placing implementing the functionality of <code>adjustDisplayScale</code> within the <code>onCreate()</code> like this and it did not work:</p>
  
  <pre><code>@Override
  public void onCreate() {
      super.onCreate();
  
      Context context = getApplicationContext();
      Resources res = context.getResources();
      Configuration configuration = res.getConfiguration();
  
      configuration.fontScale = 1f;
      DisplayMetrics metrics = res.getDisplayMetrics();
  
      WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);
      wm.getDefaultDisplay().getMetrics(metrics);
      metrics.scaledDensity = 1f;
      configuration.densityDpi = (int) res.getDisplayMetrics().xdpi;
      context = context.createConfigurationContext(configuration);
  
      SoLoader.init(this, /* native exopackage */ false);
  }
  </code></pre>
  
  <p>A potentially promising answer included the following:</p>
  
  <pre><code>protected override void AttachBaseContext(Context @base) {
      var configuration = new Configuration(@base.Resources.Configuration);
      configuration.FontScale = 1f;
      var config =  Application.Context.CreateConfigurationContext(configuration);
      base.AttachBaseContext(config);
  }
  </code></pre>
  
  <p>But when I tried to utilize this, I got errors about not recognizing the symbol @base.</p>
  
  <p>Some background... I've done 99% of my work on this project in JavaScript / React Native and I have almost no understanding about things like <code>Resources</code>, <code>Context</code>, <code>Configuration</code>, and <code>DisplayMetrics</code> associated with Android development AND the last time I wrote code in Java was 10 years ago. I've spent a number of agonizing hours trying to figure this out and any help would be <strong>greatly</strong> appreciated.</p>
  
  <p>ps. I am well-aware that accessibility settings exist for a good reason so please spare me the diatribe I've seen in so many "answers" on why I need to fix my UI to work with accessibility settings rather than disable them.</p>