create ColorStateList - Android Graphics

Android examples for Graphics:Create Color

Description

create ColorStateList

Demo Code


//package com.java2s;

import android.content.res.ColorStateList;

public class Main {
    public static ColorStateList createColorStateList(int normal,
            int selected, int pressed, int focused, int unable) {
        int[] colors = new int[] { pressed, focused, selected, focused,
                unable, normal, normal };
        int[][] states = new int[7][];
        states[0] = new int[] { android.R.attr.state_pressed,
                android.R.attr.state_enabled };
        states[1] = new int[] { android.R.attr.state_enabled,
                android.R.attr.state_focused };
        states[2] = new int[] { android.R.attr.state_selected };
        states[3] = new int[] { android.R.attr.state_focused };
        states[4] = new int[] { android.R.attr.state_window_focused };
        states[5] = new int[] { android.R.attr.state_enabled };
        states[6] = new int[] {};
        ColorStateList colorList = new ColorStateList(states, colors);
        return colorList;
    }//from ww  w. j a  v  a 2s .co  m
}

Related Tutorials