본문 바로가기

나의 플랫폼/안드로이드

[ Android ] 버튼 이미지 변경 ( 코딩 )

336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

버튼 클릭 이벤트가 발생 했을 때, 아이콘을 변경하는 방법입니다.

기본 drawable 리소스가 존재한다는 전제하에...^^


btn.setCompoundDrawablesWithIntrinsicBounds(getResources().getDrawable(R.drawable.id), null, null, null);


매개변수는 left,top,right,down 순입니다.


xml 에선 다음과 같이 적용.

<Button

     android:layout_width="match_parent"

     android:layout_height="wrap_content"

     android:layout_weight="1"

     android:drawableLeft="@drawable/id"/>

참조 : http://stackoverflow.com/questions/4250923/how-to-change-a-buttons-icon-programmatically


그럼 오늘도 즐코딩하세요.^^