Font size of TextView in Android application changes on changing font size from native settings

Vikasdeep Singh picture Vikasdeep Singh · Nov 7, 2012 · Viewed 538.8k times · Source

I want to specify my own text size in my application, but I am having a problem doing this.

When I change the font size in the device settings, the font size of my application TextView also changes.

Answer

sandrstar picture sandrstar · Nov 7, 2012

Actually, Settings font size affects only sizes in sp. So all You need to do - define textSize in dp instead of sp, then settings won't change text size in Your app.

Here's a link to the documentation: Dimensions

However please note that the expected behavior is that the fonts in all apps respect the user's preferences. There are many reasons a user might want to adjust the font sizes and some of them might even be medical - visually impaired users. Using dp instead of sp for text might lead to unwillingly discriminating against some of your app's users.

i.e:

android:textSize="32dp"