마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

tint selector 질문

0 추천

이미지뷰에 틴트 처리해서 사용하고 있는데요.

selector를 이용해서 터치 다운 업에 따라서 색상을 변경해주고 싶은데 안되더라구요.

별도 처리가 필요한가요?

 

view.xml

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:clickable="true"
    android:orientation="vertical">


    <ImageView
        android:id="@+id/imageView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:clickable="true"
        android:duplicateParentState="true"
        android:src="@drawable/icon_menu"
        android:tint="@color/button_extend_selector"
        android:tintMode="multiply" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="TextView"
        android:textColor="@color/button_extend_selector" />
</LinearLayout>

 

button_extend.selector.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
  <item android:state_pressed="true" android:color="#52c334"/>
  <item android:state_focused="true" android:color="#52c334"/>
  <item android:color="#000000"/>
</selector>

 

 

익명사용자 님이 2018년 6월 11일 질문

2개의 답변

0 추천
xml은 문제 없어 보입니다. 혹시 ImageView에 OnClickListener는 등록 하셨나요?

또는 ImageView에 android:clickable="true"를 적용해 보시기 바랍니다.
디자이너정 (42,810 포인트) 님이 2018년 6월 11일 답변
리스너의 경우는 지금 필요없기때문에 구현하지 않았습니다.
이미지 뷰에 이미 clickable은 적용해놨습니다.
0 추천

해결했습니다.

drawable에 state_pressed 및 state_focused 가 true일때와 아닐때 bitmap을 생성 

true

<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
    android:src="@drawable/icon_menu"
    android:tint="#52c334"/>

false

<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
    android:src="@drawable/icon_menu"
    android:tint="#000000"/>

 

test.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

  <item android:state_pressed="true" android:drawable="@drawable/btn_radio_point"/>
  <item android:state_focused="true" android:drawable="@drawable/btn_radio_point"/>
  <item android:drawable="@drawable/btn_radio_nopoint"/>


</selector>

 

을 한뒤에 imageview의 tint 값을 제거하고 src에 test.xml 을 추가했더니 되네요.

좀 돌아서 하긴했는데 해결되었습니다.

 

익명사용자 님이 2018년 6월 11일 답변
...