Is there any visual feedback for toolbar icons when disabling them on Android?
I've added some icons to my app's action bar by doing:
item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
item.setIcon(drawable);
Sometimes, I need to disable an item, so I call:
item.setEnabled(false);
This indeed disables the item, i.e. it doesn't react to touches any more but disabling it doesn't change the icon imagery. On desktop systems I'm used to disabled items being grayed out or something so that the user can clearly see that the item is disabled but this doesn't seem to happen with Android's Toolbar
widget when calling setEnabled(false)
. The icon image stays the same. It just doesn't react to touches any more.
Of course, I can manually add a grey filter on the drawable to make it appear grey but I'm not sure if this is the way to go.
That's why I'd like to ask: Is it intended behaviour that toolbar icons don't change their look when disabling them on Android?
You can create icons for both states (enabled/disabled) and add them to a selector:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/icon_enabled" android:state_enabled="true"/>
<item android:drawable="@drawable/icon_disabled" android:state_enabled="false"/></selector>
then replace the drawable with the selector and Android should handle the rest.
EDIT: I don't think there's any element in Android that will automatically change its appearance just by enabling/disabling it. I've been using the mentioned solution every time I have a button/icon that is not always clickable.