Convert String hex color value to int color - Android Graphics

Android examples for Graphics:Color Value

Description

Convert String hex color value to int color

Demo Code


//package com.java2s;
import android.graphics.Color;

import java.util.regex.Pattern;

public class Main {

    public static int HextoColor(String color) {
        // #ff00CCFF
        String reg = "#[a-f0-9A-F]{8}";
        if (!Pattern.matches(reg, color)) {
            color = "#00ffffff";
        }//from w  w w .ja  v a2s.  c  om

        return Color.parseColor(color);
    }
}

Related Tutorials