Its painfully bad to change graphic of a TextView drawable programmatically. If you want android:drawableRight, android:drawableLeft, android:drawableTop or android:drawableBottom to change based on the TextView state it is possible to do it simply the same way you would specify to a android:background attribute. There should be no need to change any of these properties programmatically. It is much more neat & efficient to deal with this in the layout file.
e.g. in your layout file:
android:drawableRight="@drawable/icon_accept_selector"
icon_accept_selector is an XML state list drawable file:
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/icon_accept" android:state_enabled="true"/> <item android:drawable="@drawable/icon_accept_disabled" android:state_enabled="false"/> </selector>
Advertisements