ToggleButton inherits from TextView so you can display drawings on four borders of text. You can use this to display the icon you want on top of the text and hide the actual text
<ToggleButton android:id="@+id/toggleButton1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:drawableTop="@android:drawable/ic_menu_info_details" android:gravity="center" android:textOff="" android:textOn="" android:textSize="0dp" />
The result compared to the usual ToggleButton looks like

The second parameter should use ImageSpan to actually replace the text with an image. It looks a little better since the icon is in the correct position, but cannot be done directly with the xml layout.
You create a simple ToggleButton
<ToggleButton android:id="@+id/toggleButton3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:checked="false" />
Then set the "text" programmatically
ToggleButton button = (ToggleButton) findViewById(R.id.toggleButton3); ImageSpan imageSpan = new ImageSpan(this, android.R.drawable.ic_menu_info_details); SpannableString content = new SpannableString("X"); content.setSpan(imageSpan, 0, 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); button.setText(content); button.setTextOn(content); button.setTextOff(content);
The result is in the middle here - the icon is located a little lower, as it replaces the text.

zapl 03 Sep '13 at 18:39 2013-09-03 18:39
source share