Java tutorial
//package com.java2s; //License from project: Open Source License import android.graphics.Color; public class Main { public static int getColor(String colorHex) { if (!colorHex.startsWith("#")) colorHex = "#" + colorHex; int a; int r; int g; int b; if (colorHex.length() == 7) { a = 0xFF; r = Integer.parseInt(colorHex.substring(1, 3), 16); g = Integer.parseInt(colorHex.substring(3, 5), 16); b = Integer.parseInt(colorHex.substring(5, 7), 16); } else if (colorHex.length() == 9) { a = Integer.parseInt(colorHex.substring(1, 3), 16); r = Integer.parseInt(colorHex.substring(3, 5), 16); g = Integer.parseInt(colorHex.substring(5, 7), 16); b = Integer.parseInt(colorHex.substring(7, 9), 16); } else return Color.BLACK; int c = Color.argb(a, r, g, b); return c; } }