我正在根据Marshmallow源代码自定义设置应用程序; 示例:操作栏的颜色,状态栏,EditTextView,对话框按钮等。 阅读材料设计指南后,我知道colorAccent的修改可以满足我。 所以,我这样做:
<style name="Theme.SettingsBase" parent="@android:style/Theme.Material.Settings" />
<style name="Theme.Settings" parent="Theme.SettingsBase">
<item name="android:colorAccent">@color/red</item>
</style>
不幸的是,它无法发挥作用,它们的颜色仍然很深。
源代码: http://androidxref.com/6.0.0_r1/xref/packages/apps/Settings/res/values/themes.xml
答案 0 :(得分:0)
请在应用自己的风格后首先检查是否有主题覆盖操作,特别是调用applyStyle / setTheme。
虽然Theme.Settings设置了windowDrawsSystemBarBackgrounds,但是colorPrimaryDark无法工作,因为PhoneWindow.java和ActivityManager.java中有以下代码:
// PhoneWindow.java
protected ViewGroup generateLayout(DecorView decor) {
// Non-floating windows on high end devices must put up decor beneath the system bars and
// therefore must know about visibility changes of those.
if (!mIsFloating && ActivityManager.isHighEndGfx()) { // Shield off this flag if isFloating or lowEndGfx
if (!targetPreL && a.getBoolean(
R.styleable.Window_windowDrawsSystemBarBackgrounds,
false)) {
setFlags(FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS,
FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS & ~getForcedWindowFlags());
}
}
...
}
private WindowInsets updateColorViews(WindowInsets insets, boolean animate) {
if (!mIsFloating && ActivityManager.isHighEndGfx()) {
...
}
...
}
// ActivityManager.java
static public boolean isHighEndGfx() {
return !isLowRamDeviceStatic() &&
!Resources.getSystem().getBoolean(com.android.internal.R.bool.config_avoidGfxAccel);
}
/** @hide */
public static boolean isLowRamDeviceStatic() {
return "true".equals(SystemProperties.get("ro.config.low_ram", "false"));
}
我只是更改了PhoneWindow的政策,该政策没有检查ro.config.low_ram属性以快速实现我的期望。