How to apply two different styles to one element in android? How to apply two different styles to one element in android? xml xml

How to apply two different styles to one element in android?


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>


A style under Android can have a parent style.

So just have MyActivityTextView define GeneralTextView as parent style, and change/add style properties.

Then you can use MyActivityTextView for some views and GeneralTextView for the others.

It's described in Defining Styles.


You can extend one style with another in your style.xml:

<style name="current_weekday_white" parent="current_day_white">    <item name="android:textColor">#FFABAB</item></style>