sajjad soltani
sajjad soltani

Reputation: 56

How to change all view text size in android

I want to add an item on menu to adjust the application font size. and if font size be changed by user with this feature all the font sizes of texts in views of application be changed.

Upvotes: 0

Views: 160

Answers (1)

Sarthak Gandhi
Sarthak Gandhi

Reputation: 2170

I use this method to adjust the font size of my application but here i am keeping it stable at scale 1 which you can change accordingly.

    public void adjustFontScale(Configuration configuration) {
    configuration.fontScale = (float) 1;
    DisplayMetrics metrics = getResources().getDisplayMetrics();
    WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);
    wm.getDefaultDisplay().getMetrics(metrics);
    metrics.scaledDensity = configuration.fontScale * metrics.density;
    getBaseContext().getResources().updateConfiguration(configuration, metrics);
}

Just change the configuration.fontScale to any value you like and call it in onCreate. Hope this helps.

Upvotes: 1

Related Questions