?attr/colorPrimary 支持版本?

?attr/colorPrimary support version?

我的处境相当严重。我已经使用 ?attr/colorPrimary 构建了我的 entire 应用程序来选择背景形状的颜色,因为我设计了一种动态更改主题和颜色的方法。这在 5.0 上完美运行,但在所有 4.x 设备上,?attr/colorPrimary 会使应用程序崩溃。为什么 Android studio 不提醒开发人员这种不兼容性?

有支持版本吗?attr/colorPrimary?

我相信它是在 Android Lollipop - API 21.

之后添加的

至少这个link表明它是在API 20和21之间添加的:

https://developer.android.com/sdk/api_diff/21/changes/android.R.attr.html

attr/colorPrimary 只需指向当前主题中定义的colorPrimary。

我不确定您是如何实现主题的。但是您可以创建自己的属性...只有当您支持多个主题时,此选项才有用。

如果你的主题是单一的,我相信你可以用颜色代替它。

API 21:

Material design style

Notifications are drawn with dark text atop white (or very light) backgrounds to match the new material design widgets. Make sure that all your notifications look right with the new color scheme. If your notifications look wrong, fix them:

Use setColor() to set an accent color in a circle behind your icon image. Update or remove assets that involve color. The system ignores all non-alpha channels in action icons and in the main notification icon. You should assume that these icons will be alpha-only. The system draws notification icons in white and action icons in dark gray.

colorPrimary is already part of AppCompat as of version 21 并回到 API 7。您的问题出在您的主题代码上。

问题是 Android 代码中的一个小故障。 See this,它与 完全 不一样,但原因是。

万一有人遇到这个问题,我想解释一下我的解决方法。

删除“?attr/color(主要、深色或重音)”的所有实例,并尝试模仿每个个体中每个个体元素的效果activity。这不是一个完整的解决方法,但对我来说它有效。 Google 确实需要解决这个问题。如果您知道更好的解决方法,请告诉我,只要有效,我就会接受它作为更好的答案。