안드로이드 개발 질문/답변
(글 수 45,052)
<color name="set_on_color">#333333</color> <color name="set_off_color">#666666</color>
변경하고자 하는 소스는 아래와 같습니다.
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
switch (v.getId()) {
case R.id.EditText01:
editText01.setTextColor(R.color.set_on_color);
editText01.setBackgroundResource(R.drawable.clock_start_on);
editText02.setTextColor(R.color.set_off_color);
editText02.setBackgroundResource(R.drawable.clock_end_off);
timeSetting = CommonIds.START_TIME_SETTING;
break;
case R.id.EditText02:
editText02.setTextColor(R.color.set_on_color);
editText02.setBackgroundResource(R.drawable.clock_end_on);
editText01.setTextColor(R.color.set_off_color);
editText01.setBackgroundResource(R.drawable.clock_start_off);
timeSetting = CommonIds.END_TIME_SETTING;
break;
}
}
return false;
}
setBackgroundResource 잘 적용되어서 바뀌는데
.setTextColor 는 적용이 안됩니다....고수님들의 조언 부탁드립니다..ㅠㅠ




setBackgroundResource 에 설정하는것은 Resource ID 이므로 작동합니다만
setTextColor 는 Resource ID 가 아닌 Color 값을 받습니다.
둘다 int 형이라서 빌드시에 에러는 안나지만
작동하지 않습니다
그러므로 다음과 같이 수정해야 합니다.
setTextColor(getResources().getColor(R.color.set_on_color))
Resource ID 를 컬러 값으로 바꿔서 넣어줘야 작동합니다.