appcompat 库样式是如何工作的

how does appcompat library styling work

我对 appcompat 库中的样式如何工作感到很困惑。

根据here

We now use the support implementation of Toolbar/ActionBar on all platforms meaning that we no longer read any android: attributes related to the action bar.

For apps which already have existing appcompat setups, this means that you should remove your v14+ themes which re-set the same values in the android namespace. Please note, this is ONLY applicable for styles/widgets which affect the action bar.

For most apps, you now only need one theme declaration, in values/

所以这是我的问题:

如果我想在 API 14+ 中使用 material 设计 ActionBar,我可以只使用 appcompat_v7 中提供的 ActionBar/Toolbar 并将其样式设置为通用值/删除了 "android:" 命名空间的文件夹?但为什么我看到有人在下面编写代码:

<style name="MyTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    ....
    <item name="windowContentOverlay">@null</item>
    <item name="android:windowContentOverlay">@null</item>
    ....
</style>

为什么 "android:" 命名空间在那里?上面的代码和使用 value-v21、value-v14、文件夹有什么区别?

有人可以解释或指导我找到正确的来源吗?

是的,如果您使用 AppCompat v21+,您只需要一个父主题为 Theme.AppCompat 的主题(或 Theme.AppCompat.Light 之类的子主题),而您 不需要 需要 android: 命名空间属性用于操作 bar/window 相关标志,也不需要单独的 v14、v20 等主题。AppCompat 在所有 API 中提供的顶级属性的完整列表级别可以在 AppCompat R.styleable Theme.

中找到

互联网上的大部分代码(包括 developer.android.com 网站的部分内容)仍然是为 v21 之前的 AppCompat 编写的,确实 需要 android: 和无前缀版本。