Android日历颜色来自';日历颜色';与真实日历颜色不同

Android日历颜色来自';日历颜色';与真实日历颜色不同,android,colors,calendar,Android,Colors,Calendar,我使用列CALENDAR\u color作为int获取颜色,但颜色与日历中显示的真实颜色不同。 事实上,它的颜色相似,但要轻得多!为什么会这样 谢谢初始化变量 private View mView; mView = (View) findViewById(R.id.mView); 使用变量绑定视图 private View mView; mView = (View) findViewById(R.id.mView); 日历内容提供商将返回颜色代码,您必须编写代码才能获取日历的颜色代码 S

我使用列
CALENDAR\u color
作为
int
获取颜色,但颜色与日历中显示的真实颜色不同。
事实上,它的颜色相似,但要轻得多!为什么会这样


谢谢

初始化变量

private View mView;
mView = (View) findViewById(R.id.mView);
使用变量绑定视图

private View mView;
mView = (View) findViewById(R.id.mView);
日历内容提供商将返回颜色代码,您必须编写代码才能获取日历的颜色代码

String calendarColorCode = "-5997854";
int mColorCode = (0xff000000 + Integer.parseInt(calendarColorCode));
转换int-color

String calendarColorCode = "-5997854";
int mColorCode = (0xff000000 + Integer.parseInt(calendarColorCode));
在视图上应用背景色代码

viewColorCode.setBackgroundColor(mColorCode);

完成

谷歌日历应用程序对颜色进行转换。它使用硬编码的地图来搜索颜色对应。如果在地图上找不到颜色,则会应用手动变换

这是代码的简化(但功能)版本:

public final class CalendarUtils {

private static final Map<Integer, Integer> sUpdatedColors;

static {
    Map hashMap = new HashMap();
    sUpdatedColors = hashMap;
    hashMap.put(-509406, -2818048);
    sUpdatedColors.put(-370884, -765666);
    sUpdatedColors.put(-35529, -1086464);
    sUpdatedColors.put(-21178, -1010944);
    sUpdatedColors.put(-339611, -606426);
    sUpdatedColors.put(-267901, -1784767);
    sUpdatedColors.put(-4989844, -4142541);
    sUpdatedColors.put(-8662712, -8604862);
    sUpdatedColors.put(-15292571, -16023485);
    sUpdatedColors.put(-12396910, -16738680);
    sUpdatedColors.put(-7151168, -13388167);
    sUpdatedColors.put(-6299161, -16540699);
    sUpdatedColors.put(-6306073, -12417548);
    sUpdatedColors.put(-11958553, -12627531);
    sUpdatedColors.put(-6644481, -8812853);
    sUpdatedColors.put(-4613377, -5005861);
    sUpdatedColors.put(-5997854, -6395473);
    sUpdatedColors.put(-3312410, -7461718);
    sUpdatedColors.put(-3365204, -5434281);
    sUpdatedColors.put(-618062, -2614432);
    sUpdatedColors.put(-3118236, -1672077);
    sUpdatedColors.put(-5475746, -8825528);
    sUpdatedColors.put(-4013374, -10395295);
    sUpdatedColors.put(-3490369, -5792882);
    sUpdatedColors.put(-2350809, -2818048);
    sUpdatedColors.put(-18312, -765666);
    sUpdatedColors.put(-272549, -606426);
    sUpdatedColors.put(-11421879, -16023485);
    sUpdatedColors.put(-8722497, -13388167);
    sUpdatedColors.put(-12134693, -16540699);
    sUpdatedColors.put(-11238163, -12627531);
    sUpdatedColors.put(-5980676, -8812853);
    sUpdatedColors.put(-2380289, -7461718);
    sUpdatedColors.put(-30596, -1672077);
    sUpdatedColors.put(-1973791, -10395295);
    sUpdatedColors.put(-2883584, -2818048);
    sUpdatedColors.put(-831459, -765666);
    sUpdatedColors.put(-1152256, -1086464);
    sUpdatedColors.put(-1076736, -1010944);
    sUpdatedColors.put(-672219, -606426);
    sUpdatedColors.put(-1914036, -1784767);
    sUpdatedColors.put(-4208334, -4142541);
    sUpdatedColors.put(-8670655, -8604862);
    sUpdatedColors.put(-16089278, -16023485);
    sUpdatedColors.put(-16738937, -16738680);
    sUpdatedColors.put(-16606492, -16540699);
    sUpdatedColors.put(-12483341, -12417548);
    sUpdatedColors.put(-12624727, -12627531);
    sUpdatedColors.put(-8878646, -8812853);
    sUpdatedColors.put(-5071654, -5005861);
    sUpdatedColors.put(-7527511, -7461718);
    sUpdatedColors.put(-5500074, -5434281);
    sUpdatedColors.put(-2680225, -2614432);
    sUpdatedColors.put(-1737870, -1672077);
    sUpdatedColors.put(-8891321, -8825528);
    sUpdatedColors.put(-10263709, -10395295);
}

public static int getDisplayColor(int color) {
    if (sUpdatedColors.containsKey(color)) {
        return (sUpdatedColors.get(color));
    }
    if (sUpdatedColors.containsValue(color)) {
        return color;
    }
    float[] fArr = new float[3];
    Color.colorToHSV(color, fArr);
    if (fArr[2] > 0.79f) {
        fArr[1] = Math.min(fArr[1] * 1.3f, 1.0f);
        fArr[2] = fArr[2] * 0.8f;
    }
    return Color.HSVToColor(Color.alpha(color), fArr);
}

}

您还可以使用as字符串,只要它是ARGB有效代码,如“0xFF005500”

ARGB代表Alpha/Red/Green/Blue,知道了这一点,您可以轻松地将#FF8866之类的十六进制(即RGB)代码转换为argb0xffff8866


在给出的示例中,红色代码为FF,绿色代码为88,蓝色代码为66。默认情况下,这将是一种不透明颜色,因此将FF指定为alpha,结果是ARGB代码为0xFFFF8866。

我建议使用DDMS拍摄所需颜色的屏幕截图,然后使用paint或photoshop获取该颜色,然后手动设置该颜色。我不需要手动设置,我希望通过获取真实颜色来匹配该颜色,如果系统将添加新的颜色怎么办?您是否能够解决此问题?我也遇到了同样的问题。我认为色差是某种可以逆转的功能的结果。但是,我找不到它,因为更改似乎不一致。@Juler,我查看了Google日历代码,发现他们正在使用Color DB获取和设置日历/事件颜色。我必须说,我认为这是一个过度的杀伤力,所以我离开了当前的实现。感谢您回复这样一个旧的线程。这很有趣,不过颜色不应该相同吗?你能给我指一个推荐人吗?我刚刚发现谷歌日历应用程序(Kitkat和older)显示的颜色与我得到的颜色相同(比新的谷歌日历更亮)。新的日历应用程序似乎使用了一些材质样式。这很好,有文档记录吗?没有,上一次发布的日历源()只包含手动转换(请参阅其getDisplayColorFromColor方法)。但我查看了当前的calendar apk以查找地图颜色对应关系。有关信息:calendarColorCode是来自event(CalendarContract.Events.calendar\u color)的calendar\u颜色,而不是来自calendar(CalendarContract.Calendars.calendar\u color)!之后,此建议对我有效。不幸的是,颜色与谷歌日历中的颜色不匹配:(