<!-- android:Theme.Light @android:style/Theme.Light -->
这2种引用有何区别?
我的理解:
theme本身也是一种style,是针对的整个界面(Application or Activity)的效果,而style针对的是某一个控件(Button, TextView)的效果。
android:Theme.Light 的引用就当做是一种主题式的引用,而@android:style/Theme.Light 这样的引用就是当做style的引用。
<style name="BrowserThemeBase" parent="android:Theme.Light">
<item name="*android:windowTranslucentStatus">opaque</item>
</style>
<style name="BrowserThemeBase.BrowserTheme">
<!-- <item name="*android:windowTranslucentStatus">opaque</item>
*miui refer to a non-public attribute -->
<item name="*android:hidePopupArrow">true</item>
<item name="android:actionBarStyle">@style/ActionBarNoTitle</item>
<item name="android:windowBackground">@color/white</item>
<item name="android:colorBackground">#FFFFFFFF</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
</style>
注意下面的写法,经过测试发现,对于下面的写法:以BrowserThemeBase 已经有的属性为主,然后加上新的属性:
<style name="BrowserThemeBase.Fragment" >
<item name="android:actionBarStyle">@null</item>
</style>
下面的写法,以parent 继承的为主,会忽略掉 BrowserThemeBase 这个父的属性,就是说: BrowserThemeBase中定义的不会影响BrowserThemeBase.Fragment
<style name="BrowserThemeBase.Fragment" parent="miui:Theme.Light.ActionBar.NoTitle">
<item name="android:actionBarStyle">@null</item>
</style>
通过 点(.)来继承的这种方式 只适用与自定义的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来实现了~