On Mar 16, 2:16 pm, Mark Murphy <mmur...@commonsware.com> wrote:
> Nathan wrote:
> > The current ToggleButton extends TextView and not ImageButton, so you
> > can't switch images, just text.
>
> First, ToggleButton extends CompoundButton, like you were proposing for
> your own implementation.
>
> Second, you should be able to replace the image used by ToggleButton.
>
> Step #1: Clone the following resources from your SDK into your project:
>
> res/drawable/btn_toggle.xml
> res/drawable/btn_toggle_bg.xml
> res/drawable-*/btn_toggle_on.9.png
> res/drawable-*/btn_toggle_off.9.png
>
> Step #2: Modify btn_toggle_bg.xml to point to your @drawable/btn_toggle
> rather than the built-in one.
>
> Step #3: Change btn_toggle_*.9.png as needed
>
> Step #4: Set btn_toggle_bg as the background of the ToggleButton, in
> your layout or via a style
>

Thanks. This is great stuff.

I was actually looking for a more reusable widget, so I wouldn't have
to go through the above procedure three times if I wanted three
toolbar buttons. This gives me a starting point.

Something like this:

        <ToggleImageButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        srcOff="@drawable/door_closed"
        srcOn="@drawable/door_open"/>
        <ToggleImageButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        srcOff="@drawable/light_off"
        srcOn="@drawable/light_on"/>
        <ToggleImageButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        srcOff="@drawable/intact_walnut"
        srcOn="@drawable/cracked_walnut"/>

I believe I will have to write some code, though maybe not much, to
read those attributes and use them.

Nathan

-- 
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