一.概述
通過繼承機制,可以利用已有的style來定義新的style。所定義的新的style型不僅擁有新定義的item,而且還同時擁有舊的item。我們稱已存在的用來派生新的style為父style。由新定義的style,又稱為子style。 比如:
<style name="pickprof_guide_text"> <item name="android:textSize">16.0sp</item> <item name="android:textColor">#ff333333</item></style><style name="pickprof_guide_text_small" parent="@style/pickprof_guide_text"> <item name="android:textSize">13.0sp</item> </style>
二、兩種繼承方式
方式一:通過parent屬性用來繼承android已經定義好的style。例如:
<style name="XDialog" parent="android:Theme.Dialog"> <item name="android:windowBackground">@drawable/pop_frame</item> </style>
方式二:如果要繼承自訂的style,不需要通過parent屬性,只要style的name以需要繼承的style的name開始後跟新的style的name,中間用“.”隔開。注意:這種方式只適用與自訂的style繼承。例如:
<!-- Base style for animations. This style specifies no animations. --> <style name="Animation" /> <!-- Standard animations for a non-full-screen window or activity. --> <style name="Animation.Dialog"> <item name="windowEnterAnimation">@anim/dialog_enter</item> <item name="windowExitAnimation">@anim/dialog_exit</item> </style>