Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the TextAppearance programmatically

I'm trying to set the TexAppearance of a TextView programmatically. I've look at SetTextApparence and at the TextView constructor 3rd parameter.

I can set one of Android style:

lvTextView.SetTextAppearance(Context, Android.Resource.Style.TextAppearanceMedium); 

But I cannot figure how to set my own app style. What is the syntax to reference my styles?

like image 515
user2483710 Avatar asked Sep 09 '13 20:09

user2483710


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.

What is textappearance in Android textview?

This attribute can be used to set the style for text content in a TextView without affecting other styling attributes on the same TextView object. In this tutorial, we will learn how to apply textAppearance to TextView objects.

How to change text on textview in Java?

TextView is used to hold text and basically application developer set text on textView using activity_main.xml layout file but sometimes developer needs some different task so you can change textView text easily through MainActivity.java programming file.

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 do I change the text appearance of a material component?

Set up a (small) selection of TextAppearance s your app will use (or use/extend from MaterialComponent’s styles) and reference these directly from your views Create styles setting any attributes not supported by TextAppearance (which themselves specify one of your TextAppearances ). Perform any unique styling directly in your layout.


1 Answers

Supposing your style is like this:

<style name="MyStyle" parent="@android:style/Widget.TextView">
    <item name="android:textStyle">bold</item>
    ...
</style>

You can set the TextView's appearance programatically as:

TextView textViewTitle = (TextView) findViewById(R.id.text_view_title); // Your TextView
textViewTitle.setTextAppearance(this, R.style.MyStyle);
like image 66
Shobhit Puri Avatar answered Nov 03 '22 12:11

Shobhit Puri