martin treurnicht
martin treurnicht

Reputation: 1253

ImageButton set src as StateListDrawable

I'm trying to create a ImageButton that changes it's icon based on wether it's enabled or not. I've created the following file:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/icn_increase_inactive" />
    <item android:state_enabled="true" android:drawable="@drawable/icn_increase_active" />
</selector>

When toggling the state between enabled and disabled nothing changes. Also i tried to create my own ImageButton that extends ImageButton and try and manually switch the state, but within the ImageButton it's loading the drawable as a BitmapDrawable and not as a StateListDrawable. When loading outside of the image button it works as a StateListDrawable though. Any ideas?

Upvotes: 0

Views: 372

Answers (1)

martin treurnicht
martin treurnicht

Reputation: 1253

I can't believe this, after struggling with this for so long. All i needed to do is swap the items around. The the default state should always be at the bottom it seems. Hope this saves someone else a lot of time

Upvotes: 1

Related Questions