Thursday, July 15, 2010

Views do not have an "android:enabled" attribute

So trying to use it for View-derived classes in your layout XML does nothing.

Trying to use non-existent attributes normally causes a compiler error, but not in the case of android:enabled. I'm guessing that this is because it is valid for a very few types not used in layout files - e.g., Menu, Application - and the schema isn't very tightly enforced.

Therefore, if you want a button or something to begin life disabled until some event occurs, you can't do that in XML... you have to do it in code, i.e. use setEnabled(false) in your onCreate().

(I found this out the hard way... spent two hours convinced I'd found a bug in StateListDrawable or because my apparently-disabled buttons were being drawn just as if they were enabled. Which of course they were. Doh!).

No comments:

Post a Comment