안녕하세요~
폭우가 내린 맑은 하늘을 만끽할수 있는 월요일입니다.ㅎ
xml을 사용하지 못하기 떄문에
자바 코드로 selector 을 구현해야 하는데요..
이미지가 있는 경우라면,
public static StateListDrawable imageChange(Drawable normal, Drawable press) {
StateListDrawable imageDraw = new StateListDrawable();
imageDraw.addState(new int[] { android.R.attr.state_pressed }, press);
imageDraw.addState(new int[] { -android.R.attr.state_pressed }, normal);
return imageDraw;
}
요래 구현을 했는데
이미지가 없이 컬러값으로 구현하려면 ColorStateList를 써봤는데 요놈은 TextView.setTextColor 에만 먹히는 놈인듯 하네요.
받는 인자가 같은 int형인데 setBackgroundColor에는 먹히지 않네요
혹시 다른 방법을 알고 계시는분 있으신가요??
제발 이런 프로젝트는 다시는 하고 싶지 않네요...에휴,..
자답입니다..
그냥 컬러값으로 Drawable객체 생성해서 똑같이 하면 되네요...
꼼수인지는 모르겠으나...-0-;;
public static StateListDrawable colorChange(String normalColor, String pressColor) {
Drawable normalDraw = new ColorDrawable(Color.parseColor(normalColor));
Drawable pressDraw = new ColorDrawable(Color.parseColor(pressColor));
StateListDrawable colorDraw = new StateListDrawable();
colorDraw.addState(new int[] { android.R.attr.state_pressed }, pressDraw);
colorDraw.addState(new int[] { -android.R.attr.state_pressed }, normalDraw);
return colorDraw;
}




.....그냥 color을 이용해서 Drawable 객체를 만들어서 stateListDrawable을 사용하면 되려나요..-0-ㅋㅋ
갑자기 문득 든 생각이네요;;