I have custom textAppearance defined in my themes. My Theme looks like this
<style name="Theme.MyApp" parent="Theme.MaterialComponents.Light">
.....
<item name="textAppearanceHeadline3">@style/TextAppearance.MySpark.Headline3</item>
.....
</style>
Here is the style TextAppearance.MyApp.Headline3
<style name="TextAppearance.MyApp.Headline3" parent="TextAppearance.MaterialComponents.Headline3">
<item name="fontFamily">@font/avenir_next_demi</item>
<item name="android:textSize">40sp</item>
<item name="android:gravity">left|top</item>
<item name="android:textStyle">bold</item>
<item name="android:textColor">?attr/colorOnSurface</item>
</style>
Works for XML
<com.google.android.material.textview.MaterialTextView
android:textAppearance="?attr/textAppearanceHeadline3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/add_product_description"/>
WORKS for programmatically referencing style
textView.setTextAppearance(R.style.TextAppearance_MyApp_Headline3)
DOESN'T WORK FOR When I want to apply textAppearance programmatically using attr, I couldn't find a way yet for something like this.
textView.setTextAppearance(R.attr.textAppearanceHeadline3)
I would like to use attr which helps me in switching different themes.