'[기타강좌] 버튼 눌렀을 때와 땟을때의 이미지 처리 방법'에 해당되는 글 1건

  1. 2010.08.04 [기타강좌] 버튼 눌렀을 때와 땟을때의 이미지 처리 방법
04.Anddoid2010. 8. 4. 14:13
반응형
개발 Q&A에서 가끔 보던 질문이고 저 또한 질문 했던 내용 입니다.

이미지 버튼을 사용시 버튼을 클릭했을때와 땟을때의 처리를 해결 못해서 기본 안드로이드 버튼만
사용중이었습니다.

해결을 하려고 setBackgroundResource도 생각했었습니다만...

setBackgroundResource를 사용했을경우에는 버튼을 클릭했을경우엔 이미지가 바뀌지만
땟을경우에 그이미지가 그대로 남아있어서 스레드를 돌릴까도 생각도 했었는데요...

몇주전까지만해도 구글링을 해서도 찾지 못했던 내용 이었는데 오늘 그 해답을 찾았습니다 ㅠ.ㅠ

다른 api내용 찾다가 우연히 발견하게 되었습니다.

res/layout/main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:gravity="center" xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <TextView android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:text="@string/hello" />

    <ImageButton android:id="@+id/imgBtn"
    android:background="@+drawable/playbutton_click"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
    </ImageButton>
</LinearLayout>


res/drawable/playbutton_click.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_focused="false" android:state_pressed="true"
        android:drawable="@drawable/btn1" />
    <item android:drawable="@drawable/btn" />
</selector>

drawable의폴더에는
버튼이 눌러졌을때의이미지와 버튼을 땟을때의 이미지파일이 존재하여야 합니다.




이렇게 간단하게 해결될 문제였답니다 ㅠ.ㅠ

많이 허접한 내용이지만 아직도 해결 못하신분들을위해 적어 봤습니다.
Posted by 1010