I have a TextView and I want to apply a Style which I use for all TextView elements plus another style which I only use within a specific Activity. Is there any possibility to do that?
There are many ways to make multiple styles inside android TextView and in this example I have made multiple style with three different ways using HTML tags and Html. fromHtml().
Create and apply a style To create a new style or theme, open your project's res/values/styles.xml file. For each style you want to create, follow these steps: Add a <style> element with a name that uniquely identifies the style. Add an <item> element for each style attribute you want to define.
To change default themes go to File and click on Settings. A new Settings dialog will appear, like this. Under the Appearance & Behaviour -> Appearance, you will find Theme. Choose the right theme from the drop-down and click on Apply and then Ok.
Just a little piece of information that might add to the overall value of the question - shamelessly copied from: http://developer.android.com/guide/topics/ui/themes.html#DefiningStyles
If you want to inherit from styles that you've defined yourself, you do not have to use the parent attribute. Instead, just prefix the name of the style you want to inherit to the name of your new style, separated by a period. For example, to create a new style that inherits the CodeFont style defined above, but make the color red, you can author the new style like this:
<style name="CodeFont.Red">
<item name="android:textColor">#FF0000</item>
</style>
Notice that there is no parent attribute in the tag, but because the name attribute begins with the CodeFont style name (which is a style that you have created), this style inherits all style properties from that style. This style then overrides the android:textColor property to make the text red. You can reference this new style as @style/CodeFont.Red.
You can continue inheriting like this as many times as you'd like, by chaining names with periods. For example, you can extend CodeFont.Red to be bigger, with:
<style name="CodeFont.Red.Big">
<item name="android:textSize">30sp</item>
</style>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With