注意下面的写法,经过测试发现,对于下面的写法:以BrowserThemeBase 已经有的属性为主,然后加上新的属性:
通过 点(.)来继承的这种方式 只适用与自定义的style继承。但是这句话似乎和我的测试结果有些出入,不管了,能用就行吧。然后在android官方文档找到了这个说明:
Note: This technique for inheritance by chaining together names only works for styles defined by your own resources. You can't inherit Android built-in styles this way. To reference a built-in style, such as TextAppearance, you must use the parent attribute.
对这句话:This technique for inheritance by chaining together names only works for styles defined by your own resources. 做一点解释:
比如:
<style name="GreenText" parent="@android:style/TextAppearance"> <item name="android:textColor">#00FF00</item> </style> GreenText是我自己定义的,那么我后面就可以使用点继承这种方式了,如下:
<style name="GreenText.Title"> <item name="android:textSize">12sp</item> </style> 这样的话,我的 GreenText.Title 既包含了 GreenText 中定义的属性,也包含 GreenText.Title 中添加的属性。
对这句话 You can't inherit Android built-in styles this way. To reference a built-in style, such as TextAppearance, you must use the parent attribute. 做点解释:
比如系统中有个属性叫:@android:style/TextAppearance,你就不能这样用:
<style name="@android:style/TextAppearance.Title"> <item name="android:textSize">12sp</item> </style>
如果你想使用系统的属性,你就只能通过继承安卓系统中的属性,通过parent来实现了~