Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable font scaling in RN for Android?

Simply using allowFontScaling={false} fixes this on iOS, but I'm unsure how to set this on Android.

Also, for anyone that's not familiar with RN and is coming here from the Android tag, I don't think I can easily change from to dp font scaling or whatever, so is there a way I can do it globally in my app somehow?

Thanks!

like image 915
Tallboy Avatar asked Mar 12 '16 22:03

Tallboy


People also ask

How do I prevent Android device display size scaling in my app?

How do I prevent Android device Display size scaling in my app? Change the system display size programatically Android N. Disabling an app or activity zoom if Setting -> Display -> Display size changed to Large or small.

How do I stop system font size changing effects to Android application?

Prevent-system-font-size-changing-effects-to-androidForms Android MainActivity. cs, override the Resources and set the configuration to default to restrict the font size effect on application. Resources. UpdateConfiguration() has been deprecated in API 25.

What is font scaling?

1. Font scaling is an alternate term used to describe a scalable font or vector font. 2. Font scaling is a printer feature that allows the font to be scaled by the printer instead of in the document program.


1 Answers

Please Update ManiApplication.java file

import android.view.WindowManager;
import android.content.res.Configuration;
import android.content.Context;
import android.util.DisplayMetrics;

After super.onCreate(); method put adjustFontScale(getApplicationContext(),getResources().getConfiguration());

Like follow

  @Override
  public void onCreate() {
    super.onCreate();
    adjustFontScale(getApplicationContext(),getResources().getConfiguration());
}

And at the end add the following function

public void adjustFontScale(Context context, Configuration configuration) {
    if (configuration.fontScale != 1) {
        configuration.fontScale = 1;
        DisplayMetrics metrics = context.getResources().getDisplayMetrics();
        WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        wm.getDefaultDisplay().getMetrics(metrics);
        metrics.scaledDensity = configuration.fontScale * metrics.density;
        context.getResources().updateConfiguration(configuration, metrics);
    }
}
like image 96
Nisarg Thakkar Avatar answered Oct 03 '22 01:10

Nisarg Thakkar