Example usage for android.graphics Color parseColor

List of usage examples for android.graphics Color parseColor

Introduction

In this page you can find the example usage for android.graphics Color parseColor.

Prototype

@ColorInt
public static int parseColor(@Size(min = 1) String colorString) 

Source Link

Document

Parse the color string, and return the corresponding color-int.

Usage

From source file:Main.java

public static int parseColor(String colorString) {
    int color = 0;
    try {/*  w ww  . j a v a 2s  . c  om*/
        color = Color.parseColor(colorString);
    } catch (Exception e) {
        // e.printStackTrace();
    }
    return color;
}

From source file:Main.java

public static int parseColor(String colorStr) {
    int color = 0xff000000;
    try {//from  w w  w.j  a v a2  s.c o  m
        color = Color.parseColor(colorStr);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return color;
}

From source file:Main.java

public static int getColorLight(int categoryId) {

    switch (categoryId) {
    case 1:/*w  ww.ja  v  a  2  s . c om*/
        return Color.parseColor("#dcedc8");
    case 2:
        return Color.parseColor("#b3e5fc");
    case 3:
        return Color.parseColor("#ffe0b2");
    }
    return -1;
}

From source file:Main.java

public static ColorStateList GetColorStateListFromHex(String hexValue) {
    int colorAsInt = Color.parseColor(hexValue);
    return ColorStateList.valueOf(colorAsInt);
}

From source file:Main.java

public static int getScoreColor(float pc) {
    if (pc >= .8) {
        return Color.parseColor("#66FF66");
    } else if (pc >= .5) {
        return Color.parseColor("#E5E500");
    } else {/*from   w w  w . j  a  va  2s.  c o  m*/
        return Color.parseColor("#FF0033");
    }
}

From source file:Main.java

/**
 * Parse whiteColor//from w ww .jav  a2s . c  o m
 *
 * @return
 */
public static int parseWhiteColor() {
    return Color.parseColor("#FFFFFF");
}

From source file:Main.java

public static int parseColor(String colorString) {
    try {//from w w  w .ja  va  2  s . com
        return Color.parseColor(colorString);
    } catch (IllegalArgumentException e) {
        if (isShortColorCode(colorString)) {
            return parseShortColorCode(colorString);
        } else {
            return Color.BLACK;
        }
    }
}

From source file:Main.java

public static int convertNameToColor(String name) {
    name = name.substring(0, name.lastIndexOf('.'));
    return Color.parseColor(name);
}

From source file:Main.java

public static int getEdgeColor(int color) {
    String reflectColorStr = Integer.toHexString(color);
    String rgbStr = reflectColorStr.substring(2);
    return Color.parseColor("#00" + rgbStr);
}

From source file:Main.java

/**
 * Get color code from a string//from  w  w w .  ja v  a2  s  . c  o m
 * @param color The hex color string
 * @return The color code
 */
public static int getColor(String color) {
    return Color.parseColor(String.format("#%s", color));
}