5
votes

I am trying to call getIcon on a Preference declared in xml for android. I am calling it in the onCreate for the preference Activity after all the resources have been inflated.

The icon shows up but if I do findPreference(key) then it calls getIcon and on that preference the icon returned is null.

Am I missing something?

Preference doesn't resolve icons set from XML until it's bound for the first time. You could extend Preference, manually load the icon from the AttributeSet supplied to the constructor, and pass that to setIcon(int). Or you could postpone the getIcon() call until the preference has been displayed on screen. - alanv