I am trying to create a Drawable from
android.R.drawable.list_selector_background and mutate it so that I
may change some of the drawables states for the StateListDrawable that
is returned. I would like to be able to change the default enabled
state drawable for the StateListDrawable to a different drawable but
keep the other states for this Drawable.
StateListDrawable stateListDrawable = (StateListDrawable)
getContext().getResources().getDrawable
(android.R.drawable.menuitem_background);
stateListDrawable = (StateListDrawable)
stateListDrawable.mutate();
I originally tried calling this from onSizeChanged, so that I can
generate a correctly sized background for my custom drawable, as well
as within my view's constructor. Each time, I get a
NullPointerException from within the StateListDrawable.mutate method
(stack trace included below indicates down into the NinePatch that
must be used for one of the state drawables).
Do I need to wait until a later time to mutate the drawable, or
perhaps do more initialization of the drawable (tried setBounds but
with no success) before mutation?
07-28 11:46:12.312: ERROR/AndroidRuntime(1319):
java.lang.NullPointerException
07-28 11:46:12.312: ERROR/AndroidRuntime(1319): at
android.graphics.Paint.<init>(Paint.java:202)
07-28 11:46:12.312: ERROR/AndroidRuntime(1319): at
android.graphics.NinePatch.<init>(NinePatch.java:60)
07-28 11:46:12.312: ERROR/AndroidRuntime(1319): at
android.graphics.drawable.NinePatchDrawable$NinePatchState.<init>
(NinePatchDrawable.java:226)
07-28 11:46:12.312: ERROR/AndroidRuntime(1319): at
android.graphics.drawable.NinePatchDrawable.mutate
(NinePatchDrawable.java:201)
07-28 11:46:12.312: ERROR/AndroidRuntime(1319): at
android.graphics.drawable.DrawableContainer.mutate
(DrawableContainer.java:237)
07-28 11:46:12.312: ERROR/AndroidRuntime(1319): at
android.graphics.drawable.StateListDrawable.mutate
(StateListDrawable.java:222)
...
...
Thanks much for any assistance,
Mike
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---