get Pressed Color Ripple Drawable - Android Graphics

Android examples for Graphics:Color

Description

get Pressed Color Ripple Drawable

Demo Code


//package com.java2s;
import android.content.res.ColorStateList;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.RippleDrawable;

public class Main {
    public static RippleDrawable getPressedColorRippleDrawable(
            int normalColor, int pressedColor) {
        return new RippleDrawable(getPressedColorSelector(normalColor,
                pressedColor), getColorDrawableFromColor(normalColor), null);
    }/*  www.  j  ava  2s . c o m*/

    public static ColorStateList getPressedColorSelector(int normalColor,
            int pressedColor) {
        return new ColorStateList(
                new int[][] { new int[] { android.R.attr.state_pressed },
                        new int[] { android.R.attr.state_focused },
                        new int[] { android.R.attr.state_activated },
                        new int[] {} }, new int[] { pressedColor,
                        pressedColor, pressedColor, normalColor });
    }

    public static ColorDrawable getColorDrawableFromColor(int color) {
        return new ColorDrawable(color);
    }
}

Related Tutorials