Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TextAppearance property of TextView in Android

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.

like image 471
N Sharma Avatar asked Jun 16 '14 06:06

N Sharma


People also ask

What is TextAppearance in Android?

TextAppearance allows you to define text-specific styling while leaving a View 's style available for other uses. Note, however, that if you define any text attributes directly on the View or in a style, those values would override the TextAppearance values.

Which is not attribute of TextView?

Not the attribute of TextView tag does not allow together editing.


2 Answers

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.

like image 122
Shubham Srivastava Avatar answered Oct 11 '22 13:10

Shubham Srivastava


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.

like image 38
Rod_Algonquin Avatar answered Oct 11 '22 12:10

Rod_Algonquin