That dude
That dude

Reputation: 389

How to change state:activated after tapping on another image view?

I have five icons inside five different ImageViews, i wanted to change the icons once the user tap on them, i got it by android:state_activated="true" and by adding two different icons for each source, it worked but now i want the images o go back to the previous image when user tap on a different icon.

here's my code: image-changeable.xml :

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/homeiconbig" android:state_activated="true" />
    <item android:drawable="@drawable/homeicon" />
</selector> 

MainActivity:

view.setActivated(true);

Upvotes: 1

Views: 1403

Answers (2)

pqtuan86
pqtuan86

Reputation: 59

How about you change your code in MainActivity to

boolean isActivated = view.isActivated();
view.setActivated(!isActivated);

Upvotes: 0

nik
nik

Reputation: 345

Add this line in image-changeable.xml:-

<item android:drawable="@drawable/homeicon" android:state_activated="false" />

and In Main Activity try this:-

 view.setActivated(false);

Upvotes: 1

Related Questions