Reputation: 1137
I would like to set dynamically styles for TextView. Basing on that what I found it seems not possible (unless something lately changed).
Ok, but what about working in opposite direction. Ex. I have the following style definition:
<style name="MyTextStyle" parent="@android:style/Widget.Holo.TextView">
<item name="android:textSize">@dimen/text_big</item>
<item name="android:textColor">@android:color/holo_blue_light</item>
<item name="android:textStyle">italic</item>
</style>
And now I would like to have the following code (something like that):
myTextView.setTextColor (R.styles.MyTextStyle.getTextColor)
Simply I don't define color in java code but read the current value from xml file (but not from any xml file but from styles.xml just to have guarantee that style definition is the same everywhere).
Moreover it would be great if my code would select the correct style definition if I change the app theme.
How to do that?
And of course the same I would like to repeat for textSize and textStyle (italic, bold etc).
Any idea?
Upvotes: 0
Views: 169
Reputation: 1137
Perhaps it's not the best idea to answer own questions, but as I've found the answer perhaps it will be useful for someone one day...
The solution is:
myTextView.setTextAppearance(myTextView.getContext(), R.styles.MyTextStyle);
Upvotes: 1