Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between TextView's style and android:textAppearance attributes?

If I define my TextView as:

 <TextView         style="@android:style/TextAppearance.DeviceDefault.Large"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:text="Hello World!" /> 

it is basically the same as doing:

 <TextView         android:textAppearance="@android:style/TextAppearance.DeviceDefault.Large"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:text="Hello World!" /> 

I know that style is some kind of broader qualifier (i.e. one can't set all attributes in android:textAppearance) but then it raises the question: why bother? Is there any advantage of using android:textAppearance over style?

like image 620
Miro Kropacek Avatar asked Jul 22 '16 02:07

Miro Kropacek


People also ask

What is text attribute in Android?

The TextAttribute class defines attribute keys and attribute values used for text rendering. TextAttribute instances are used as attribute keys to identify attributes in classes handling text attributes. Other constants defined in this class can be used as attribute values.

How do I bold text in Android XML?

Change Text Style of TextView to BOLD in XML Layout File textStyle attribute of TextView widget accepts on of these values: "bold" , "italic" or "normal" . To change the style to bold, you have to assign textStyle with "bold" .

Why does textappearance override textview appearance?

Because the text appearance is checked first, any attributes defined either directly on a view or in a style will override the text appearance. There’s one other caveat to be aware of with TextAppearance which is that is supports a subset of styling attributes that TextView offers.

How does textview work in Android?

Essentially TextView first looks if you’ve supplied android:textAppearance, if so it loads that style and applies any properties it specifies. Later on, it then loads all attributes of the view (which remember, includes the style) and applies them.

How to declaratively style text on Android?

Understanding how to declaratively style text on Android. When styling text in Android apps, TextView offers multiple attributes and different ways to apply them. You can set attributes directly in your layout, you can apply a style to a view, or a theme to a layout or perhaps set a text appearance.

How to dynamically change the textview style in Android Studio?

In our demonstration, we dynamically changed the TextView style by tapping on it. To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio. We demonstrated the application in Kotlin, so make sure you select Kotlin as the primary language while creating a New Project.


1 Answers

From Styles and Themes https://developer.android.com/guide/topics/ui/look-and-feel/themes#textappearance

One limitation with styles is that you can apply only one style to a View. In a TextView, however, you can also specify a TextAppearance attribute which functions similarly to a style

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.

like image 173
onmyway133 Avatar answered Nov 09 '22 17:11

onmyway133