Then write your own custom Drawable subclass that does what you want.

On Thu, Jul 5, 2012 at 10:04 PM, lianyu li <ice...@gmail.com> wrote:

> But sometimes it's really not enough to express states only with booleans,
> actually I have the same issue with Nick, that is "adding custom states in
> a list of enums". Not sure whether Android has plan to add such feature.
>
>
> On Fri, Jul 6, 2012 at 10:18 AM, Dianne Hackborn <hack...@android.com>wrote:
>
>> Yes this must be booleans.  There is no way to express anything else in
>> StateListDrawable.
>>
>>
>> On Thu, Jul 5, 2012 at 6:21 AM, li lianyu <ice...@gmail.com> wrote:
>>
>>> It's seems that currently Android doesn't support non-boolean state. You
>>> can verify it by adding another item with non-a state in selector pair. I
>>> assume Android evaluates true/false only by checking whether corresonding
>>> state attribute be in drawableState returned by onCreateDrawableState.
>>>
>>>
>>> On Saturday, January 21, 2012 3:40:41 AM UTC+8, Nick wrote:
>>>>
>>>> I have searched around and I found good examples on adding custom
>>>> boolean states to a drawable but I am having issues adding a state
>>>> that is a list of enums.  I am sure most of my problems lie within the
>>>> onCreateDrawableState call so I have a few questions.
>>>>
>>>> 1) Is the extraSpace param to onCreateDrawableState the number of
>>>> additional int[] that I would like to add or the size of the int[]? So
>>>> since I am just adding MODE I should just be increasing extraSpace by
>>>> 1 and not by MODE.length?
>>>> 2) I don't quite understand the mergeDrawableStates method.  If I put
>>>> it in an IF statement I am getting what I expect, but I think I am
>>>> just getting lucky.  I don't feel my IF check is correct.  My initial
>>>> assumption was that I don't do a check and always call
>>>> mergeDrawableStates but then the drawable never changes.  I have seen
>>>> where if the extra state is a boolean then the if statement checks for
>>>> that.  I don't quite know what to do about an enum.
>>>> 3) When I do get it working, my ic_button_a is drawn correctly.
>>>> However every time when ic_button_c is getting drawn, ic_button_c is
>>>> resized and stretch to fit the View which includes a background
>>>> graphic that is larger than ic_button_c.  ic_button_a and ic_button_a
>>>> are the same size.
>>>>
>>>> I have my custom view:
>>>>         <com.pkg.CustomView
>>>>             android:background="@drawable/**ic_button_bg"
>>>>             android:src="@drawable/ic_**button"
>>>>             android:layout_height="wrap_**content"
>>>>             android:layout_width="wrap_**content"/>
>>>>
>>>> which extends ImageButton.:
>>>> public class CustomView extends ImageButton {
>>>>
>>>>     private static final int[] MODE = {R.attr.mode};
>>>>     private int mMode = 1;
>>>>
>>>>     @Override
>>>>     public int[] onCreateDrawableState(int extraSpace) {
>>>>         final int[] drawableState =
>>>> super.onCreateDrawableState(**extraSpace + 1);
>>>>         if (mMode != 0) {
>>>>             mergeDrawableStates(**drawableState, MODE);
>>>>         }
>>>>         return drawableState;
>>>>     }
>>>>
>>>>     public void setMode(int mode) {
>>>>         mMode = mode;
>>>>         refreshDrawableState();
>>>>     }
>>>> }
>>>>
>>>> I am defining my modes here:
>>>> <resources>
>>>>     <declare-styleable name="CaptureButton">
>>>>         <attr name="mode">
>>>>             <enum name="a"  value="0" />
>>>>             <enum name="b"  value="1" />
>>>>             <enum name="c"  value="2" />
>>>>             <enum name="d"  value="3" />
>>>>             <enum name="e"  value="4" />
>>>>             <enum name="f"   value="5" />
>>>>             <enum name="g"  value="6" />
>>>>             <enum name="h"  value="7" />
>>>>         </attr>
>>>>     </declare-styleable>
>>>> </resources>
>>>>
>>>> My @drawable/ic_button is:
>>>> <selector 
>>>> xmlns:android="http://schemas.**android.com/apk/res/android<http://schemas.android.com/apk/res/android>"
>>>>
>>>>     
>>>> xmlns:app="http://schemas.**android.com/apk/res/com.pkg<http://schemas.android.com/apk/res/com.pkg>">
>>>>
>>>>     <item app:mode="c"  android:drawable="@drawable/**ic_button_c" />
>>>>
>>>>     <item android:drawable="@drawable/**ic_button_a" />
>>>> </selector>
>>>
>>>  --
>>> You received this message because you are subscribed to the Google
>>> Groups "Android Developers" group.
>>> To post to this group, send email to android-developers@googlegroups.com
>>> To unsubscribe from this group, send email to
>>> android-developers+unsubscr...@googlegroups.com
>>> For more options, visit this group at
>>> http://groups.google.com/group/android-developers?hl=en
>>>
>>
>>
>>
>> --
>> Dianne Hackborn
>> Android framework engineer
>> hack...@android.com
>>
>> Note: please don't send private questions to me, as I don't have time to
>> provide private support, and so won't reply to such e-mails.  All such
>> questions should be posted on public forums, where I and others can see and
>> answer them.
>>
>>
>>  --
>> You received this message because you are subscribed to the Google
>> Groups "Android Developers" group.
>> To post to this group, send email to android-developers@googlegroups.com
>> To unsubscribe from this group, send email to
>> android-developers+unsubscr...@googlegroups.com
>> For more options, visit this group at
>> http://groups.google.com/group/android-developers?hl=en
>>
>
>  --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to android-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
>



-- 
Dianne Hackborn
Android framework engineer
hack...@android.com

Note: please don't send private questions to me, as I don't have time to
provide private support, and so won't reply to such e-mails.  All such
questions should be posted on public forums, where I and others can see and
answer them.

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to