create Enable Disable Selector Drawable - Android Graphics

Android examples for Graphics:Drawable Operation

Description

create Enable Disable Selector Drawable

Demo Code


//package com.java2s;

import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
import android.graphics.drawable.StateListDrawable;

public class Main {

    public static Drawable createEnableDisableSelector(int radius,
            int disableColor, int enableColor) {
        // ???? selector
        StateListDrawable stateListDrawable = new StateListDrawable();
        stateListDrawable.addState(/*from  w ww .j  ava 2s.c  o  m*/
                new int[] { android.R.attr.state_enabled },
                createShape(radius, enableColor));
        stateListDrawable.addState(new int[] {},
                createShape(radius, disableColor));
        return stateListDrawable;
    }

    public static Drawable createShape(int radius, int color) {
        GradientDrawable normalDrawable = new GradientDrawable();
        normalDrawable.setCornerRadius(radius);
        normalDrawable.setColor(color);
        return normalDrawable;
    }
}

Related Tutorials