android style的继承方式 点(.)和parent

一.概述

通过继承机制,可以利用已有的style来定义新的style。所定义的新的style型不仅拥有新定义的item,而且还同时拥有旧的item。我们称已存在的用来派生新的style为父style。由新定义的style,又称为子style。
比如:

1
2
3
4
5
6
7
<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。例如:

1
2
3
<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继承。
例如:

1
2
3
4
5
6
7
<!-- 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>

转自:
http://blog.csdn.net/mingli198611/article/details/7254275