Android style inheritance method: point (.) and parent detailed explanation and examples
1. Overview
Through the inheritance mechanism, the existing style can be used to define a new style. The defined new style not only has the newly defined item, but also has the old item. We call existing styles used to derive new styles as parent style. The newly defined style, also known as the sub-style. for example:
<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>
Two inheritance methods
Method 1: Use parent attribute to inherit the style already defined by Android. For example:
<style name="XDialog" parent="android:"> <item name="android:windowBackground">@drawable/pop_frame</item> </style>
Method 2: If you want to inherit a custom style, you do not need to pass the parent attribute. As long as the style name starts with the name of the style that needs to be inherited, followed by the name of the new style, separated by "." in the middle. Note: This method only applies to custom style inheritance. For example:
<!-- Base style for animations. This style specifies no animations. --> <style name="Animation" /> <!-- Standard animations for a non-full-screen window or activity. --> <style name=""> <item name="windowEnterAnimation">@anim/dialog_enter</item> <item name="windowExitAnimation">@anim/dialog_exit</item> </style>
Thank you for reading, I hope it can help you, thank you for your support for this site!