get Checked Selector as StateListDrawable - Android Graphics

Android examples for Graphics:State List Drawable

Description

get Checked Selector as StateListDrawable

Demo Code


//package com.java2s;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.StateListDrawable;

public class Main {
    public static StateListDrawable getCheckedSelector(Context context,
            int idChecked, int idNormal) {
        StateListDrawable bg = new StateListDrawable();
        Drawable normal = idNormal == -1 ? null : context.getResources()
                .getDrawable(idNormal);/*from ww  w  . java2s .com*/
        Drawable selected = idChecked == -1 ? null : context.getResources()
                .getDrawable(idChecked);
        bg.addState(new int[] { android.R.attr.state_checked }, selected);
        bg.addState(new int[] {}, normal);
        return bg;
    }
}

Related Tutorials