[Android] XML drawable 을 코드로 만들기(xml selector를 java code로 변환)

Posted by Find my true self Fimtrus
2014.02.20 11:25 Programming/Android
StateListDrawable states = new StateListDrawable();
states.addState(new int[] {android.R.attr.state_pressed},
    getResources().getDrawable(R.drawable.pressed));
states.addState(new int[] {android.R.attr.state_focused},
    getResources().getDrawable(R.drawable.focused));
states.addState(new int[] { },
    getResources().getDrawable(R.drawable.normal));

imageView.setImageDrawable(states);  //YOUR IMAGE HERE
//AND FOR BUTTON
 button.setBackgroundDrawable(states);//FOR BUTTON
이 댓글을 비밀 댓글로
    • 2018.04.16 15:05
    비밀댓글입니다