Android棒棒糖接触色

时间:2016-01-12 18:26:58

标签: android android-5.0-lollipop

如何选择联系人徽章的颜色。使用什么算法?

enter image description here

2 个答案:

答案 0 :(得分:5)

它没有保存。它使用Contact name字符串的哈希码来确定颜色。

示例:

String name = "Harish";
int colors[] = new int[] { Color.RED, Color.GREEN, Color.BLUE};

int chosenColor = colors[Math.abs(name.hashCode()) % colors.length];

我从这个answer

中学到了什么

答案 1 :(得分:1)

您可以试试像这样的颜色生成器..

    protected void Application_Error(object sender, EventArgs e)
    {
        var lastException = Server.GetLastError();

        var wrappedContext = new HttpContextWrapper(Context);
        wrappedContext.Response.StatusCode = (lastException as HttpException)?.GetHttpCode() ?? 500;
        wrappedContext.Response.Clear();
        wrappedContext.Response.TrySkipIisCustomErrors = true;
        wrappedContext.Server.ClearError();

        var routeData = new RouteData();
        routeData.Values.Add("area", "");
        routeData.Values.Add("controller", "Error");
        routeData.Values.Add("action", "Index");
        routeData.Values.Add("httpResponseCode", Context.Response.StatusCode);

        IController errorController = DependencyResolver.Current.GetService<ErrorController>();
            errorController.Execute(new RequestContext(wrappedContext, routeData));
    }