Home » Android » TextAppearance property of TextView in Android

TextAppearance property of TextView in Android

Posted by: admin June 15, 2020 Leave a comment


I am working on android application where I am using TextView to display the text on screens.

I am using this property for the TextView to set the size of the text android:textAppearance="?android:attr/textAppearanceMedium".

Do I need to set the size of that text also or it does automatically manage by Android OS ?

Thanks in advance.

How to&Answers:

In Android text elements there is a default which is applied first (similar to webpages). If you wish to override those and define your own, then you must explicitly set them. android:textAppearance is one such override, but there are other attributes you can override individually (as opposed to as an aggregate)… you’ll want to see the documentation for that.


Yes, the resizing is done automatically in the background. While using attributes like android:textAppearance it directly uses the predefined specific sp values for the textSize as-

android:textAppearance="?android:textAppearanceSmall" => 14sp

android:textAppearance="?android:textAppearanceMedium" => 18sp

android:textAppearance="?android:textAppearanceLarge" => 22sp

Thus it adjusts the values automatically based on the screen density and the user’s preference in such a way that it seems equal on all the devices say for example formula for dp values: px = dp * (dpi/160), the similar case is for the sp values used only for fonts, it utilizes the same concept only difference being it may vary due to user’s fontSize preference as set in settings.

I haven’t used that :attr/ type as it may or may not be used and serves the same purpose because the system resource tool knows that an attribute resource is expected in this context, you do not need to explicitly state the type.

Following are the links to external resources:

textAppearance equivalent sp size, “Android Developers, Google + article”

Accessing Resource, “look for :attr”


Do I need to set the size of that text also or it does automatically manage by Android OS ?

Nope, Using android:textAppearance="?android:attr/textAppearanceMedium will make all of the text in medium size on different devices. So that means your app text on different devices will have the same size and weight.

Setting the size of each text would require calculation to be able to achieve same size and weight.