Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

styles multiple inheritance

Tags:

android

styles

Is there any way to make a style inherit from multiple other styles, instead of just being limited to:

<style name="WidgetTextBase">     <item name="android:typeface">serif</item>     <item name="android:textSize">12dip</item>     <item name="android:gravity">center</item> </style>  <style name="BOSText" parent="WidgetTextBase">     <item name="android:textColor">#051C43</item> </style> 

I would like BOSText to also inherit from:

<style name="WidgetTextHeader">     <item name="android:textStyle">bold</item> <style> 
like image 933
NPike Avatar asked Jul 15 '10 16:07

NPike


2 Answers

Styles do not support multiple inheritance (at least not as of Android 3.2).

The official docs say:

If you use the dot notation to extend a style, and you also include the parent attribute, then the parent styles override any styles inheritted through the dot notation.

like image 57
Jonas Avatar answered Sep 22 '22 07:09

Jonas


You can only inherit one style. However, you can also make the inherited style inherit from another style, and so on:

<style name="WidgetTextBase">     <item name="android:typeface">serif</item>     <item name="android:textSize">12dip</item>     <item name="android:gravity">center</item> </style>  <style name="WidgetTextHeader" parent="WidgetTextBase">     <item name="android:textStyle">bold</item> </style>  <style name="BOSText" parent="WidgetTextHeader">     <item name="android:textColor">#051C43</item> </style> 

You can't inherit more than one style, but you can set up an inheritance chain.

like image 44
Captain Kenpachi Avatar answered Sep 22 '22 07:09

Captain Kenpachi