How to set font scale in my own android application?

可紊 提交于 2019-11-30 15:39:24

The code below will allow to change for the application only the font scale. On second line, the code "configuration.fontScale=(float) 1;" will have to chabge to meet your needs. The defaults are scaling with 0.15 step, having default 1.

Place it before calling setContentView(R.layout.yourlayout)

Configuration configuration = getResources().getConfiguration();
configuration.fontScale=(float) 1; //0.85 small size, 1 normal size, 1,15 big etc

DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
metrics.scaledDensity = configuration.fontScale * metrics.density;
getBaseContext().getResources().updateConfiguration(configuration, metrics);

Hope this helps!

I think what you are looking for is to apply a theme to your activity or view

Please take a look at the android docs Themes

Translated for Xamarin....

        Android.Content.Res.Configuration configuration = Resources.Configuration;
        configuration.FontScale = (float)1; //0.85 small size, 1 normal size, 1,15 big etc

        Android.Util.DisplayMetrics metrics = new DisplayMetrics();
        this.WindowManager.DefaultDisplay.GetMetrics(metrics);
        metrics.ScaledDensity = configuration.FontScale * metrics.Density;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!