styles.xml vs themes.xml
这两个文件其实没有区别。实际上,在 values 文件夹下,你可以取任意文件名,只要文件扩展名是 xml 且根元素是 <resources>
即可。strings.xml、colors.xml 亦同。
style vs theme
style 只应用到对应的一个元素上;theme 会逐级向下传递,应用到所有的子层级。例如,在 AndroidManifest.xml
中给一个 FooActivity
指定 android:theme="@style/MyTheme"
,在 MyTheme
中指定了对话框主题 <item name="alertDialogTheme">@style/MyFooDialogStyle</item>
,如果一个对话框 FooDialog
在 FooActivity
中,它就会服从 @style/MyFooDialogStyle
所指定的样式。