Hi all,

Mark Murphy wrote:
Thanks for the info.  However, I still don't understand how to put an
image on a toggle button.

You can't, at least not in the same fashion that you put an image on an
ImageButton.

Based on what I am seeing, you will need to:

1. Clone btn_toggle.xml from data/res/drawable from some Android SDK
platform directory into your project.

2. Clone all of the versions of btn_toggle_off.9.png and
btn_toggle_on.9.png (one per density) from data/res/drawable-* into your
project.

3. Apply your desired bitmap to the .9.png files, adjusting the nine-patch
border if needed.

4. Assign your @drawable/btn_toggle as the background for your ToggleButton.

Depending on what you are after, there may be a simpler way:

 ToggleButton tb = new ToggleButton(mContext);
 Drawable d = getResources().getDrawable(YOURDRAWABLEHERE);
 d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
 tb.setCompoundDrawables(null,d,null,null);

This will put the specified drawable inside the togglebutton next to the text - swap around the "d" and "null" depending on how you want it to display.

Note, this will keep the original look of the button and just show the image inside it.

                        Good luck / Jonas
-- 
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

Reply via email to