1. 继承: 在运用系统自带的风格时只想改变其中一些小的方面,当然,我们可以直接在布局文件中控件的属性里重写这个属性即可。因为在布局文件中定义的属性的优先级>我们在style中定义的属性。
<style name="GreenText" parent="@android:style/TextAppearance">
<item name="android:textColor">#00FF00</item>
</style>
若是继承自己定义的style时可以使用下面格式,继承于CodeFont.但不适用于继承系统自带的style
<style name="CodeFont.Red">
<item name="android:textColor">#FF0000</item>
</style>
2. style内容:可以上Android developer查找特定类的XML attributes,还有些属性是不属于任何view,只属于window的.
However, if you apply a style to a View that does not support all of the style properties, the View will apply only those properties that are supported and simply ignore the others.
你所定义的style,并不一定适用于所有的视图,有些属性试图并不支持,这个时候,视图将只会运用它所支持的属性,忽略掉剩下的属性.
3. 应用style:
<color name="custom_theme_color">#b0b0ff</color>
<style name="CustomTheme" parent="android:Theme.Light">
<item name="android:windowBackground">@color/custom_theme_color</item>
<item name="android:colorBackground">@color/custom_theme_color</item>
</style>
(Note that the color needs to supplied as a separate resource here because the
android:windowBackground
attribute only supports a reference to another resource; unlikeandroid:colorBackground
, it can not be given a color literal.)
注意到android:windowBackground
只支持对另一资源的引用,这与android:colorBackground
不一样.